How LeetCode finds the first and last positions of elements in a sorted array
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