simple java solution


  • 0
    public int[] twoSum(int[] numbers, int target) {
            int smaller = 0, bigger = numbers.length-1;
            
            while(numbers[smaller]+numbers[bigger] != target){
                if(numbers[smaller]+numbers[bigger] > target) bigger--;
                else if (numbers[smaller]+numbers[bigger] < target) smaller++;
            }
            
            return new int[]{smaller+1, bigger+1};
        }

Log in to reply
 

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