首页 > 其他 > 详细

leetcode 1 两数之和

时间:2020-02-05 19:29:52      阅读:67      评论:0      收藏:0      [点我收藏+]
        int [] two_num(int [] nums,int target){
            HashMap<Integer, Integer> num_indx = new HashMap<Integer, Integer>();
            int [] ans = new int [2];
            for(int i=0;i<nums.length;i++){
                int another = target - nums[i];
                if(num_indx.containsKey(another)){
                    ans[0] = i;
                    ans[1] = num_indx.get(another);
                    return ans;
                }
                num_indx.put(nums[i],i);
            }
            return ans;
        }

https://leetcode-cn.com/problems/two-sum/

这个要注意读题,明确说明是两数之和。。

 

leetcode 1 两数之和

原文:https://www.cnblogs.com/superxuezhazha/p/12264495.html

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