Problem · Array
Leftmost Binary Search Match
Learn this problemProblem statement
Return the smallest index whose value equals target in the nondecreasing array nums, or -1 when the target is absent.
Function
leftmostIndex(nums: int[], target: int) → intExamples
Example 1
nums = [1,2,2,2,4]target = 2return = 1The first of three equal values is at index one.
Example 2
nums = [1,3,5]target = 2return = -1The lower-bound position does not contain the target.
Constraints
0 <= nums.length <= 100000numsis sorted in nondecreasing order.- The required time complexity is
O(log n).