Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 333bd36

Browse files
committedJan 14, 2020
Add solution #1207
1 parent 2e4f123 commit 333bd36

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 1207. Unique Number of Occurrences
3+
* https://leetcode.com/problems/unique-number-of-occurrences/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of integers arr, write a
7+
* function that returns true if and only
8+
* if the number of occurrences of each
9+
* value in the array is unique.
10+
*/
11+
12+
/**
13+
* @param {number[]} numbers
14+
* @return {boolean}
15+
*/
16+
var uniqueOccurrences = function(numbers) {
17+
const map = new Map();
18+
numbers.forEach(n => map.set(n, map.has(n) ? map.get(n) + 1 : 1));
19+
const occurrences = Array.from(map.values());
20+
return new Set(occurrences).size === occurrences.length
21+
};

0 commit comments

Comments
 (0)
Please sign in to comment.