Java-LeetCode1207. 独一无二的出现次数-HashMap&HashSet
- 算法
- HashMap + HashSet
public boolean uniqueOccurrences(int[] arr) {
HashMap<Integer, Integer> map = new HashMap<>();
for (int x : arr) {
map.put(x, map.getOrDefault(x, 0) + 1);
}
return map.size() == new HashSet<Integer>(map.values()).size();
}
正浩创新EcoFlow公司福利 515人发布

