The problem is not too difficult than previous one, for the leftmost index, assign right = mid - 1 when target == nums[mid] in order to let the pointer try to move left as it can; for the rightmost use the similar one, left = mid + 1 when target == nums[mid] and let the range as right as we can.
leetcode-34-Find First and Last Position of Element in Sorted Array
最新推荐文章于 2024-11-08 13:05:39 发布