diff --git a/34. Find First and Last Position of Element in Sorted Array.cpp b/34. Find First and Last Position of Element in Sorted Array.cpp new file mode 100644 index 0000000..6449954 --- /dev/null +++ b/34. Find First and Last Position of Element in Sorted Array.cpp @@ -0,0 +1,10 @@ +class Solution { + public: + vector searchRange(vector& nums, int target) { + const int l = lower_bound(begin(nums), end(nums), target) - begin(nums); + if (l == nums.size() || nums[l] != target) + return {-1, -1}; + const int r = upper_bound(begin(nums), end(nums), target) - begin(nums) - 1; + return {l, r}; + } +};