Unique Number of Occurrences
给一个数组, 问里面的数字的个数是不是唯一. counting问题.
class Solution {
public boolean uniqueOccurrences(int[] arr) {
Map<Integer, Integer> map = new HashMap<>();
for(int n : arr)
map.put(n, map.getOrDefault(n, 0)+1);
Map<Integer, Boolean> check = new HashMap<>();
for(int v : map.values()) {
if(check.containsKey(v))
return false;
check.put(v, true);
}
return true;
}
}