[算法系列] 两数之和——无序数组(Java)

public int[] twoSum(int[] nums, int target){
        Map map = new HashMap<>();
        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];
    }

你可能感兴趣的:(算法,算法,java)