两数之和
class Solution {
public int[] twoSum(int[] nums, int target) {
int[] res = new int[2];
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
int temp;
for(int i = 0; i < nums.length; i++) {
temp = target - nums[i];
if (map.containsKey(temp)) {
res[1] = i;
res[0] = map.get(temp);
}
map.put(nums[i], i);
}
return res;
}
}