首页 > 编程语言 > 详细

leetcode 1. Two Sum [java]

时间:2019-04-04 19:26:39      阅读:116      评论:0      收藏:0      [点我收藏+]

注意点:

  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;
    }

leetcode 1. Two Sum [java]

原文:https://www.cnblogs.com/whyaza/p/10656507.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!