Lower Bound
EasyP2Coding
nums is sorted in ascending order and may contain duplicates. Return the index of the first occurrence of k, or -1 if k is not present.
Your solution must run in O(log n) time.
Example 1
- Input
- nums = [1,2,2,2,5], k = 2
- Output
- 1
Example 2
- Input
- nums = [1,3,5], k = 4
- Output
- -1
Example 3
- Input
- nums = [7], k = 7
- Output
- 0
Constraints
- 0 <= nums.length <= 10^5
- -10^9 <= nums[i], k <= 10^9
- nums is sorted in non-decreasing order
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.