望着时间滴答滴答的流过,我不曾改变过 . . .

leetcode 1. Two Sum [java]

注意点:

  1. HashMap<Integer, Integer>
  2. return new int[]{};
  3. 3 2 4 target:6
  4. return null;
public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> m = new HashMap<>();
        for(int i = 0; i < nums.length; ++i){
            if(m.containsKey(target - nums[i]))
                return new int[]{m.get(target - nums[i]), i};
            m.put(nums[i], i);
        }
        return null;
    }
posted @ 2019-04-04 18:45  whyaza  阅读(120)  评论(0编辑  收藏  举报