Leetcode 1 2sum:
HashMap to record Key value pair, get(target-nums[i]) or put the value
Knowledge: Map to get and put and containsKey
Array for loop
space: o(1)
time: o(n)
public int[] twoSum(int[] nums, int target) {
if(nums==null||nums.length==0) return new int[]{-1,-1};
HashMap<Integer, Integer> map=new HashMap<>();
for(int i=0;i<nums.length;i++){
if(map.containsKey(target-nums[i]))
return new int[]{map.get(target-nums[i]),i};
else map.put(nums[i],i);
}
return new int[]{-1, -1};
}