// Given an array of integers, find two numbers such that they add up to a specific target number.

// 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.

// You may assume that each input would have exactly one solution.

// Input: numbers={2, 7, 11, 15}, target=9
// Output: index1=1, index2=2

public class Solution {
    public int[] twoSum(int[] numbers, int target) {
    	int len = numbers.length;

    	if(len == 0){
    		return numbers;
    	}

    	HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		int[] res = new int[2];

		for(int i = 0; i < len; i++){
			int num = numbers[i];
			map.put(num, i);
		}

		for(int i = 0; i < len; i++){
			int left = numbers[i];
			int right = target - left;
			if(map.containsKey(right) && map.get(right) != i){
				res[0] = i + 1;
				res[1] = map.get(right) + 1;
				return res;
			}
		}

    	return res;
    }
}
@@ -1,471 +1,4 @@
-// Given an array of integers, 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.%0A%0A// Input: numbers=%7B2, 7, 11, 15%7D, target=9%0A// Output: index1=1, index2=2%0A%0A
 publ
@@ -17,20 +17,17 @@
 ution %7B%0A
-    
+%09
 public i
@@ -47,20 +47,16 @@
 nt%5B%5D num
-bers
 , int ta
@@ -67,98 +67,10 @@
 ) %7B%0A
-    %09int len = numbers.length;%0A%0A    %09if(len == 0)%7B%0A    %09%09return numbers;%0A    %09%7D%0A%0A    %09Hash
+%09%09
 Map%3C
@@ -130,40 +130,14 @@
 ();%0A
-%09%09int%5B%5D res = new int%5B2%5D;%0A%0A
 %09%09for
+ 
 (int
@@ -152,266 +152,162 @@
 i %3C 
-len
+num.length
 ; i++)
+ 
 %7B%0A%09%09%09i
-nt num = numbers%5Bi%5D;%0A%09%09%09map.put(num, i);%0A%09%09%7D%0A%0A%09%09for(int i = 0; i %3C len; i++)%7B%0A%09%09%09int left =
+f (map.containsKey(target -
  num
-bers%5Bi%5D;%0A%09%09%09int right = target - left;%0A%09%09%09if(map.containsKey(right) && map.get(right) != i)%7B%0A%09%09%09%09res%5B0%5D =
+%5Bi%5D)) %7B%0A%09%09%09%09return new int%5B%5D %7Bmap.get(target - num%5Bi%5D) + 1,
  i + 1
+%7D
 ;%0A%09%09%09
-%09res%5B1%5D = map.get(right) + 1
+%7D%0A%09%09%09map.put(num%5Bi%5D, i)
 ;%0A%09%09
+%7D%0A
 %09%09re
@@ -315,43 +315,27 @@
 urn 
-res;%0A%09%09%09%7D%0A%09%09%7D%0A%0A    %09return res;%0A    
+new int%5B%5D %7B-1,-1%7D;%0A%09
 %7D%0A%7D

update two sum solution