1207. Unique Number of Occurrences
難易度
EASY
アプローチ
HashMap, HashSet
class Solution {
public boolean uniqueOccurrences(int[] arr) {
HashMap<Integer, Integer> hashMap = new HashMap<>();
HashSet<Integer> set = new HashSet<>();
for(int i : arr){
hashMap.put(i, hashMap.getOrDefault(i,0) + 1);
}
for (Map.Entry<Integer,Integer> a: hashMap.entrySet()) {
if(set.contains(a.getValue())){
return false;
}
set.add(a.getValue());
}
return true;
}
}