diff --git a/Intermediate.txt b/Intermediate.txt index 7c65ed0..20ebeb2 100644 --- a/Intermediate.txt +++ b/Intermediate.txt @@ -1768,41 +1768,3 @@ public class MergeSort { } } - -38. Find First and Last Position of Element in Sorted Array - -Problem Link: https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ - -Solution: -class Solution { -public: - vector searchRange(vector& nums, int target) { - int i = lower_bound(nums.begin(), nums.end(), target) - nums.begin(); - int j = upper_bound(nums.begin(), nums.end(), target) - nums.begin(); - if (i < nums.size() && nums[i] == target) - return {i, j - 1}; - return {-1, -1}; - - } - -// vector searchRange(vector& nums, int target) { -// int idx1 = lower_bound(nums, target); -// int idx2 = lower_bound(nums, target+1)-1; -// if (idx1 < nums.size() && nums[idx1] == target) -// return {idx1, idx2}; -// else -// return {-1, -1}; -// } - -// int lower_bound(vector& nums, int target) { -// int l = 0, r = nums.size()-1; -// while (l <= r) { -// int mid = (r-l)/2+l; -// if (nums[mid] < target) -// l = mid+1; -// else -// r = mid-1; -// } -// return l; -// } -}; \ No newline at end of file