- alias:
- parent :: [[algo-哈希]]
- siblings ::
- child ::
- refs: https://leetcode.cn/problems/two-sum/
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;
}
}