@@ -0,0 +1,1903 @@
+/**%0A *Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.%0A *%0A *The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.%0A *%0A *You may assume that each input would have exactly one solution and you may not use the same element twice.%0A *%0A *Input: numbers=%7B2, 7, 11, 15%7D, target=9%0A *Output: index1=1, index2=2%0A */%0Aclass Solution %7B%0A    public int%5B%5D twoSum(int%5B%5D numbers, int target) %7B%0A        int%5B%5D result = new int%5B2%5D;%0A        int size = numbers.length;%0A        for (int i = 0; i %3C size; i++) %7B%0A            int temp = getTempLocation(target - numbers%5Bi%5D, numbers);%0A            if (temp %3E= 0) %7B%0A                result%5B0%5D = (target - numbers%5Bi%5D %3E numbers%5Bi%5D) ? i + 1 : temp + 1;%0A                result%5B1%5D = (target - numbers%5Bi%5D %3E numbers%5Bi%5D) ? temp + 1 : i + 1;%0A            %7D %0A        %7D%0A        return result;%0A    %7D%0A    %0A    private int getTempLocation(int temp, int%5B%5D numbers) %7B%0A        int size = numbers.length;%0A        for (int i = 0; i %3C size; i++) %7B%0A            if (temp == numbers%5Bi%5D) return i;%0A        %7D%0A        return -1;%0A    %7D%0A%7D%0A%0A/**%0A * a better method%0A */%0A class Solution %7B%0A    public int%5B%5D twoSum(int%5B%5D numbers, int target) %7B%0A        int%5B%5D result = new int%5B2%5D;%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        int size = numbers.length;%0A        for (int i = 0; i %3C size; i++) %7B%0A            if (map.containsKey(target - numbers%5Bi%5D)) %7B%0A                result%5B0%5D = (target - numbers%5Bi%5D %3E numbers%5Bi%5D) ? i + 1 : map.get(target - numbers%5Bi%5D);%0A                result%5B1%5D = (target - numbers%5Bi%5D %3E numbers%5Bi%5D) ? map.get(target - numbers%5Bi%5D) : i + 1;%0A            %7D%0A            map.put(numbers%5Bi%5D, i + 1);%0A        %7D%0A        return result;%0A    %7D%0A%7D%0A

Create TwoSumIIInputArrayIsSorted.java