Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> twoSum(vector<int>& nums, int target) {
- vector<pair<int, int> > v;
- for(int i = 0; i < nums.size(); i++) {
- v.push_back(make_pair(nums[i], i));
- }
- sort(v.begin(), v.end());
- int S = 0;
- int E = nums.size() - 1;
- while(S < E) {
- if(v[S].first + v[E].first == target) {
- return {v[S].second, v[E].second};
- }
- else if(v[S].first + v[E].first > target) {
- E--;
- }
- else {
- S++;
- }
- }
- return {};
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement