Advertisement
momo2345

two sum

Aug 31st, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     vector<int> twoSum(vector<int>& numbers, int target) {
  4.         for(int i=1;i<numbers.size();i++){
  5.           int d=target-numbers[i];
  6.     int l=lower_bound(numbers.begin(),numbers.begin()+i-1,d)-numbers.begin();
  7.      if(l<numbers.size() && numbers[l]==d)
  8.          return{l+1,i+1};
  9.         }
  10.         return {-1,-1};
  11.     }
  12. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement