1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

class Solution {
public int[] twoSum(int[] nums, int target) {
HashMap<Integer, Integer> map = new HashMap<>();
int[] res = new int[2];

for(int i=0; i < nums.length; i++){
int remaining = target - nums[i];
if(map.get(remaining) == null){
map.put(nums[i], i);
}else{
res[0] = map.get(remaining);
res[1] = i;
return res;
}
}
return res;
}
}