First Position of Target
ID: 14; easy; 二分查找
Solution 1 (Java)
Notes
This is very similar to the classical binary search. However, we do not return mid when we immediately find a value because we are not sure if it is the first position. So, we only reduce the range. Eventually we have the range
[left, right]
that contains the target and we returnleft
if possible to ensure that it is the first position of target.
Last updated