Skip to content

Commit 78c9926

Browse files
authored
Update 2354-number-of-excellent-pairs.js
1 parent 8139ac0 commit 78c9926

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

2354-number-of-excellent-pairs.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
let res = 0
23+
while(num) {
24+
res += num % 2
25+
num = num >> 1
26+
}
27+
return res
28+
}
29+
};
30+
31+
// another
32+
133
/**
234
* @param {number[]} nums
335
* @param {number} k

0 commit comments

Comments
 (0)