Skip to content

Commit

Permalink
Day-26 q3: Find first and last position of element in sorted array Sn…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalpana8055 committed Jan 27, 2024
1 parent dacfac8 commit 6f621b0
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {
vector<int> ans(2,-1);
if(nums.size()==0)return ans;
int t1=lower_bound(nums.begin(),nums.end(),target)-nums.begin();
int t2=upper_bound(nums.begin(),nums.end(),target)-nums.begin();
if(t1==t2)return ans;
cout<<t1<<t2;
ans[0]=t1;
ans[1]=t2-1;
return ans;
}
};


0 comments on commit 6f621b0

Please sign in to comment.