1. Two Sum#

Code#

 1public int[] twoSum(int[] nums, int target) {
 2  Map<Integer, Integer> map = new HashMap<>();
 3  for (int i = 0; i < nums.length; i++) {
 4    if (map.containsKey(target - nums[i])) {
 5      return new int[] { i, map.get(target - nums[i]) };
 6    }
 7
 8    map.put(nums[i], i);
 9  }
10
11  return new int[] { -1, -1 };
12}