class Solution {
public boolean uniqueOccurrences(int[] arr) {
Map<Integer, Integer> map = new HashMap<>();
boolean b = true;
for (int i : arr) {
map.put(i, map.getOrDefault(i, 0)+1);
}
List<Integer> list = new ArrayList<>(map.values());
Collections.sort(list);
for (int i = 1; i < list.size(); i++) {
if (list.get(i) == list.get(i - 1)) {
b = false;
break;
}
}
return b;
}
}
OJ---独一无二的出现次数
最新推荐文章于 2024-11-11 19:42:06 发布