剑指offer Ⅱ004.只出现一次的数字
class Solution {
public int singleNumber(int[] nums) {
Map map = new HashMap<>();
for(int num : nums){
if(map.containsKey(num)){
map.put(num, map.get(num) + 1);
}else{
map.put(num, 1);
}
}
//Set> set = map.entrySet();
//for(Map.Entry entry : set)
//简写如下
for(Map.Entry entry : map.entrySet()){
if(entry.getValue() == 1){
return entry.getKey();
}
}
return 0;
}
}
关于Map.Entry


