当前位置 博文首页 > 无限迭代中......:LeetCode 1 两数之和

    无限迭代中......:LeetCode 1 两数之和

    作者:[db:作者] 时间:2021-07-19 22:29

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

    解决方案?

    class Solution {
        public int[] twoSum(int[] nums, int target) {
            Map<Integer, Integer> map = new HashMap<Integer, Integer>();
            for (int i = 0; i < nums.length; ++i) {
                if (map.containsKey(target - nums[i])) {
                    return new int[]{map.get(target - nums[i]), i};
                }
                map.put(nums[i], i);
            }
            return new int[0];
        }
    }

    ?

    cs
    下一篇:没有了