Skip to content

Commit

Permalink
Solved Day-26 q3: Find first and last position of element in sorted a…
Browse files Browse the repository at this point in the history
  • Loading branch information
Karnankita04 committed Jan 27, 2024
1 parent 08ab3ef commit 79be0c8
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
vector<int> searchRange(vector<int>& nums, int target) {

vector<int> ans(2, -1);

for(int i=0; i<nums.size(); i++){
if(nums[i]==target){
ans[0]=i;
break;
}
}

for(int i=0; i<nums.size(); i++){
if(nums[i]==target)
ans[1]=i;
}

return ans;

}
};

0 comments on commit 79be0c8

Please sign in to comment.