3 return indices of the two numbers such that they add up to a specific target.

for(int i=0;i<nums.length;i++){

  int component = target-nums[i];

  if(map.containsKey(component))

    return new int[]{map.get(component),i};

  map.put(nums[i],i);

}

posted @ 2016-09-26 18:03  得江山者得美人  阅读(182)  评论(0编辑  收藏  举报