题目:数对和
class Solution {
public List<List<Integer>> pairSums(int[] nums, int target) {
HashMap<Integer, Integer> map = new HashMap<>();
List<List<Integer>> answer = new ArrayList<List<Integer>>();
for (int num : nums) {
if (map.containsKey(target - num) && map.get(target - num) > 0){
ArrayList<Integer> list = new ArrayList<>();
list.add(target - num);
list.add(num);
answer.add(list);
map.put(target - num,map.get(target - num) - 1);
}else {
if (map.containsKey(num)){
map.put(num,map.get(num)+1);
}else
map.put(num,1);
}
}
return answer;
}
}