First Position of Target
For a given sorted array (ascending order) and atarget
number, find the first index of this number inO(log n)
time complexity.
If the target number does not exist in the array, return-1
.
Example
If the array is[1, 2, 3, 3, 4, 5, 10]
, for given target3
, return2
.
分析
二分,注意二分内移动的是end,所以可以找第一个
答案
Last updated