We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2e4f123 commit 333bd36Copy full SHA for 333bd36
solutions/1207-unique-number-of-occurrences.js
@@ -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