Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How LeetCode finds the first and last positions of elements in a sorted array

Shulou Source: shulou.com Published: 2022-06-01 13:02:46 09月26日 Update

This article mainly introduces how LeetCode finds the first and last location of elements in the sorted array. It is very detailed and has certain reference value. Interested friends must finish reading it.

First, find the first and last position 1 of the element in the sorted array, problem description

Given an array of integers nums in ascending order, and a target value target. Find out the start and end positions of the given target value in the array.

If the target value target does not exist in the array, return [- 1,-1].

2, example description example 1:

Input: nums = [5, 7, 7, 8, 8, 10], target = 8

Output: [3pd4]

Example 2:

Input: nums = [5, 7, 7, 8, 8, 10], target = 6

Output: [- 1mai Mui 1]

Example 3:

Input: nums = [], target = 0

Output: [- 1mai Mui 1]

Tip:

0

Tags: Array position example element sort goal target value input output content article title solution value interest ascending order boy buddy idea integer more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi Huawei vpn NVidia