Shawngbk / Leecode

Questions of Leecode
0 stars 0 forks source link

167. Two Sum II - Input array is sorted #77

Open Shawngbk opened 7 years ago

Shawngbk commented 7 years ago

public class Solution { public int[] twoSum(int[] numbers, int target) { Map<Integer, Integer> map = new HashMap<>(); int[] res = new int[2]; for(int i = 0; i < numbers.length; i++) { if(map.containsKey(target-numbers[i])) { res[0] = map.get(target-numbers[i])+1; res[1] = i+1; } else { map.put(numbers[i], i); } } return res; } }

Shawngbk commented 7 years ago

Amazon

Shawngbk commented 7 years ago

Amazon