Skip to content

Latest commit

 

History

History
26 lines (23 loc) · 547 Bytes

1. 两数之和.md

File metadata and controls

26 lines (23 loc) · 547 Bytes

Meta


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