第一天: 1. 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 sub = target - nums[i];
if (!map.containsKey(sub)) {
map.put(nums[i], i);
} else {
return new int[]{map.get(sub), i};
}
}
return new int[]{};
}
}