LeetCode 1. 两数之和

class Solution {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hashmap = new HashMap<>();

        int n = nums.length;

        for(int i = 0; i < n; i++){
            if(hashmap.containsKey(target - nums[i])){
                return new int[]{hashmap.get(target-nums[i]),i};
            }
            hashmap.put(nums[i],i);
        }
        return new int[0];
    }
}
原文地址:https://www.cnblogs.com/peanut-zh/p/13891691.html