-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1207. Unique Number of Occurrences
60 lines (44 loc) · 1.03 KB
/
1207. Unique Number of Occurrences
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Solution {
public boolean uniqueOccurrences(int[] arr)
{
int[] freq = new int[2001];
boolean[] occured = new boolean[2001];
for(int i:arr)
{
freq[i+1000]++;
}
for(int i: arr)
{
int val = freq[i+1000];
freq[i+1000]=0;
if(val>0)
{
if(occured[val]==true)
{
return false;
}
else
{
occured[val]=true;
}
}
}
return true;
/*
HashMap<Integer, Integer> count = new HashMap<>();
HashSet<Integer> occurrences = new HashSet<>();
for(int a : arr)
{
count.merge(a, 1, Integer::sum);
}
for(int value : count.values())
{
if (!occurrences.add(value))
{
return false;
}
}
return true;
*/
}
}