Soooooo easy c++ solution


  • 0
    M
    class Solution {
    public:
        vector<int> twoSum(vector<int>& numbers, int target) {
            int start = 0, end = numbers.size()-1;
            while(start<end){
                if(numbers[start]+numbers[end] == target)
                    return {start+1, end+1};
                else if(numbers[start] + numbers[end] < target)
                    start++;
                else
                    end--;
            }
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.