Advertisement
jibha

Untitled

Jan 21st, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class Solution {
  2. public:
  3. vector<int> twoSum(vector<int>& nums, int target) {
  4. vector<int> ans;
  5. vector<int>sorted=nums;
  6. sort(sorted.begin(),sorted.end());
  7. for(int i=0;i<nums.size();i++){
  8. if(lower_bound(sorted.begin(),sorted.end(),target-nums[i])-upper_bound(sorted.begin(),sorted.end(),7)==-1){
  9. ans.push_back(find(nums.begin(),nums.end(),nums[i])-nums.begin());
  10. ans.push_back(find(nums.begin(),nums.end(),target-nums[i])-nums.begin());
  11. }
  12. }
  13. // cout<<lower_bound(sorted.begin(),sorted.end(),7)-upper_bound(sorted.begin(),sorted.end(),7);
  14. return ans;
  15. }
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement