-
Notifications
You must be signed in to change notification settings - Fork 0
/
No_1207.ts
28 lines (23 loc) · 929 Bytes
/
No_1207.ts
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
namespace Leetcode{
export class No_1207 {
uniqueOccurrences(arr: number[]): boolean {
let map = new Map<number, number>();
arr.forEach(x => { if (!map.has(x)) map.set(x, 1); else map.set(x, map.get(x) + 1); });
let sortedArray: number[] = [];
for (const x of map.values())
sortedArray.push(x);
sortedArray.sort();
let dif = Infinity;
let ans = true;
sortedArray.forEach(x => { if (x == dif) { ans = false; return; } dif = x; })
return ans;
};
/* */
uniqueOccurrences1(arr: number[]): boolean {
let map = new Map<number, number>();
arr.forEach(x => { if (!map.has(x)) map.set(x, 1); else map.set(x, map.get(x) + 1); });
let sortedArray = new Set(map.values());
return map.size == sortedArray.size;
};
}
}