给定 nums = [2, 7, 11, 15], target = 9
因为 nums[0] + nums[1] = 2 + 7 = 9
所以返回 [0, 1]
public static int[] toSum(int [] nums , int target){
Map<Integer,Integer> map = new HashMap<>();
for(int i = 0 ; i <= nums.length -1; i++){
int complement = target - nums[i];
if(map.containsKey(complement)){
return new int [] {map.get(complement),i};
}
map.put(nums[i],i);
}
throw new IllegalArgumentException("非法的数据");
}