Skip to content

Commit a452b3b

Browse files
authored
Create 1207. Unique Number of Occurrences.java
1 parent 33ca2ba commit a452b3b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Runtime 2ms
2+
// Beats 98.10%
3+
4+
// Memory 41.69MB
5+
// Beats 28.27%
6+
7+
8+
class Solution {
9+
public boolean uniqueOccurrences(int[] arr) {
10+
HashMap<Integer,Integer> map=new HashMap<>();
11+
HashMap<Integer,Integer> res=new HashMap<>();
12+
for(int i=0;i<arr.length;i++){
13+
map.put(arr[i],map.getOrDefault(arr[i],0)+1);
14+
}
15+
for(Map.Entry<Integer,Integer> ent:map.entrySet()){
16+
if(res.containsKey(ent.getValue())){
17+
return false;
18+
}
19+
res.put(ent.getValue(),0);
20+
}
21+
return true;
22+
}
23+
}

0 commit comments

Comments
 (0)