Skip to content

Commit a625cdd

Browse files
committed
Runtime 1 ms (Top 99.73%) | Memory 40.0 MB (Top 28.38%)
1 parent 306b4df commit a625cdd

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
// Runtime: 5 ms (Top 17.42%) | Memory: 42.1 MB (Top 47.50%)
21
class Solution {
32
public boolean uniqueOccurrences(int[] arr) {
3+
Arrays.sort(arr);
4+
HashSet<Integer> set = new HashSet<>();
45

5-
var hmap = new HashMap<Integer,Integer>();
6-
for(int i:arr){
7-
hmap.put(i,hmap.getOrDefault(i,0)+1);
8-
}
9-
var arrli=new ArrayList<Integer>(hmap.keySet());
10-
var set=new HashSet<Integer>();
6+
int c = 1;
7+
for(int i = 1; i < arr.length; i++)
8+
{
9+
if(arr[i] == arr[i-1]) c++;
10+
11+
else
12+
{
13+
if(set.contains(c)) return false;
1114

12-
for(Integer i: arrli)
13-
set.add(hmap.get(i));
15+
set.add(c);
16+
17+
c = 1;
18+
}
19+
}
1420

15-
return set.size()==arrli.size() ? true : false;
21+
if(set.contains(c)) return false;
1622

23+
return true;
1724
}
1825
}

0 commit comments

Comments
 (0)