Skip to content

Commit 9512c35

Browse files
author
Dream
committedDec 14, 2021
[update]个人最优解
1 parent b7cdd20 commit 9512c35

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
class Solution {
3+
public boolean uniqueOccurrences(int[] arr) {
4+
Map<Integer, Integer> map = new HashMap(arr.length);
5+
for(int i : arr){
6+
map.put(i, map.getOrDefault(i, 0) + 1);
7+
}
8+
Map<Integer, Integer> map2 = new HashMap<>(map.size());
9+
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
10+
Integer value = entry.getValue();
11+
map2.put(value, map2.getOrDefault(value, 0) + 1);
12+
if (map2.get(value) > 1) {
13+
return false;
14+
}
15+
}
16+
return true;
17+
}
18+
}

0 commit comments

Comments
 (0)
Please sign in to comment.