← 返回 walmartlabs 的题目列表Find the First Occurrence Index in a Sorted Array with Duplicates
类型:online_judge
Problem
Given a non-decreasing sorted integer array nums (may contain duplicates) and an integer target, return the index of the first occurrence of target in the array.
If target does not exist, return -1.
I/O
Input: array nums, integer target
Output: an integer index of the leftmost (first) occurrence
Constraints
1 <= len(nums) <= 2 * 10^5
nums is sorted in non-decreasing order
nums[i] and target fit in 32-bit signed integer
Expected time complexity: O(log n)
Examples
nums = [1, 3, 5, 8, 8, 8, 8, 8, 9, 10, 15], target = 8 → 3
nums = [1,2,3], target = 4 → -1
Example
Input
11
1 3 5 8 8 8 8 8 9 10 15
8
Output
3