Posted on

Description

Submission

class Solution {
public:
    vector<int> twoSum(vector<int>& numbers, int target) {
        int i = 0, j = numbers.size() - 1;
        while(i < j) {
            int sum = numbers[i] + numbers[j];
            if(sum < target) ++i;
            if(sum == target) break;
            if(sum > target) --j;
        }
        return {i + 1, j + 1};
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *