Find First and Last Position
ARRAY
Problem
Given an array of integers nums
sorted in ascending order and an integer target
, find the starting and ending position of target
in nums
.
If target
is not found in the array, return [-1, -1]
.
Examples:
searchRange([5,7,7,8,8,10], 8) // [3,4] searchRange([5,7,7,8,8,10], 6) // [-1,-1] searchRange([1], 1) // [0,0]
Time Complexity
A target time complexity of O(n)
is desired for this problem.
Loading...