数组中只出现一次的两个数字
y总的方法学不来,只会这么简简单单粗暴的方法,哭
class Solution {
public int[] findNumsAppearOnce(int[] nums) {
HashMap<Integer, Integer> hashMap = new HashMap<>();
int[] res = new int[2];
int i = 0;
for (int x : nums) {
hashMap.put(x, hashMap.getOrDefault(x, 0) + 1);
}
for (Map.Entry<Integer, Integer> e : hashMap.entrySet()) {
if (e.getValue() == 1)
res[i++] = e.getKey();
}
return res;
}
}