Skip to content

Commit 8c57f31

Browse files
committed
Time: 3 ms (73.58%), Space: 43 MB (5.53%) - LeetHub
1 parent bf82919 commit 8c57f31

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public boolean uniqueOccurrences(int[] arr) {
3+
4+
HashMap<Integer, Integer> map = new HashMap<>();
5+
ArrayList<Integer> list = new ArrayList<>();
6+
7+
for(int i=0; i<arr.length; i++)
8+
{
9+
if(map.containsKey(arr[i]))
10+
{
11+
map.put(arr[i],map.get(arr[i])+1);
12+
}
13+
else
14+
{
15+
map.put(arr[i],1);
16+
}
17+
}
18+
19+
for(Integer i:map.keySet())
20+
{
21+
if(list.contains(map.get(i)))
22+
{
23+
return false;
24+
}
25+
list.add(map.get(i));
26+
}
27+
return true;
28+
29+
30+
}
31+
}

0 commit comments

Comments
 (0)