@@ -0,0 +1,1933 @@
+package org.pilgrim.leetcode.y2022;%0A%0Aimport java.util.Arrays;%0A%0Apublic class SumTwoInSorterArray %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09// TODO Auto-generated method stub%0A%0A%09%09int%5B%5D indexes = twoSum(new int%5B%5D %7B1,2,3,4,4,9,56,90%7D, 8);%0A%09%09System.out.println(Arrays.toString(indexes));%0A%09%7D%0A%09%0A%09public static int%5B%5D twoSum(int%5B%5D arr, int k) %7B%0A        // Validate input values%0A        if(arr == null %7C%7C arr.length %3C= 1 %7C%7C arr.length %3E 3 * 10000 %7C%7C k%3C -1000 %7C%7C k %3E 1000)%7B%0A            return null;%0A        %7D%0A        %0A        // Traverse array from both sides%0A        int%5B%5D res = new int%5B%5D %7B-1, -1%7D;%0A        int i = 0;%0A        int j = arr.length - 1;%0A        while(i %3C j)%7B%0A            int s = arr%5Bi%5D + arr%5Bj%5D;%0A            if(k == s)%7B%0A                res%5B0%5D = i+1;%0A                res%5B1%5D = j+1;%0A                break;%0A            %7D%0A            else if(k %3E s)%7B%0A                i++;%0A                while(i %3C j && arr%5Bi%5D == arr%5Bi+1%5D && arr%5Bi%5D*2 != k)%7B%0A                    i++;%0A                %7D%0A            %7D%0A            else if(k %3C s)%7B%0A                j--;%0A                while(i %3C j && arr%5Bj%5D == arr%5Bj - 1%5D && arr%5Bj%5D*2 != k)%7B%0A                    j--;%0A                %7D%0A            %7D%0A        %7D%0A        %0A        return res;%0A    %7D%0A%09%0A%09public static int%5B%5D twoSum2(int%5B%5D numbers, int target) %7B%0A        int left = 0, right = numbers.length - 1;%0A        while (left %3C right) %7B%0A            int sum = numbers%5Bleft%5D + numbers%5Bright%5D;%0A            int mid = left + (right - left) / 2;%0A            if (sum %3E target)%0A                if (numbers%5Bleft%5D + numbers%5Bmid%5D %3E target)%0A                    right = mid - 1;%0A                else%0A                    right--;%0A            else if (sum %3C target)%0A                if (numbers%5Bmid%5D + numbers%5Bright%5D %3C target)%0A                    left = mid + 1;%0A                else%0A                    left++;%0A            else%0A                return new int%5B%5D %7Bleft +1, right + 1%7D;%0A        %7D%0A        return null;%0A    %7D%0A%0A%7D%0A

Add sum two in sorted array