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 8139ac0 commit 78c9926Copy full SHA for 78c9926
2354-number-of-excellent-pairs.js
@@ -1,3 +1,35 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @param {number} k
4
+ * @return {number}
5
+ */
6
+const countExcellentPairs = function(nums, k) {
7
+ const cnt = Array(31).fill(0), set = new Set(nums)
8
+ for(const e of set) {
9
+ cnt[setBits(e)]++
10
+ }
11
+ let res = 0
12
+
13
+ for(let i = 1; i < 31; i++) {
14
+ for(let j = 1; j < 31; j++) {
15
+ if(i + j >= k) res += cnt[i] * cnt[j]
16
17
18
19
+ return res
20
21
+ function setBits(num) {
22
23
+ while(num) {
24
+ res += num % 2
25
+ num = num >> 1
26
27
28
29
+};
30
31
+// another
32
33
/**
34
* @param {number[]} nums
35
* @param {number} k
0 commit comments