leetcode 1 两数之和

        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/

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

 

posted @ 2020-02-05 17:04  超级学渣渣  阅读(98)  评论(0编辑  收藏  举报