leetcode-1207. 独一无二的出现次数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public boolean uniqueOccurrences(int[] arr) {
Arrays.sort(arr);
int n = arr.length;
boolean[] st = new boolean[n];
int count = 1;
for(int i = 1; i < n; i++){
if(arr[i] == arr[i-1]){
count++;
}else{
if(st[count] == true){
return false;
}
st[count] = true;
count = 1;
}

if(i== n-1 && st[count] == true){
return false;
}
}
return true;
}
}