34. Find First and Last Position of Element in Sorted Array
https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ 给定一个有序数组,可能包含有重复元素,问target在数组中的起始位置和结束位置,要求复杂度 \(O(logN)\) ------------------------------------------------------------------ Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] Example 2: Input: nums = [5,7,7,8,8,10], target = 5 Output: [0,0] class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { int lo = 0, hi = nums.size()-1; if (hi==-1) { vector<int> result={-1,-1}; return result; } while(lo < hi