Easy C++ Solution


  • 0
    F
        vector<int> twoSum(vector<int>& numbers, int target) {
            int left = 0, right = (int)numbers.size() - 1;
            while (left < right) {
                int sum = numbers[left] + numbers[right];
                if (sum > target) --right;
                else if (sum < target) ++left;
                else return {left + 1, right + 1};
            }
            return {0, 0};
        }
    

Log in to reply
 

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