We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3d7932c commit f9c336bCopy full SHA for f9c336b
2354-number-of-excellent-pairs.js
@@ -1,3 +1,39 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @param {number} k
4
+ * @return {number}
5
+ */
6
+const countExcellentPairs = function(nums, k) {
7
+ const n = nums.length, set = new Set()
8
+ for(const e of nums) set.add(e)
9
+ const cnt = Array(30).fill(0)
10
+ for(const e of set) {
11
+ const bc = bitCnt(e)
12
+ if(cnt[bc] == null) cnt[bc] = 0
13
+ cnt[bc] += 1
14
+ }
15
+ let res = 0
16
+ for(let i = 0; i < 30; i++) {
17
+ for(let j = 0; j < 30; j++) {
18
+ if(i + j >= k) res += cnt[i] * cnt[j]
19
20
21
+
22
+ return res
23
24
+ function bitCnt(num) {
25
26
+ while(num) {
27
+ if(num & 1) res++
28
+ num = num >> 1
29
30
31
32
33
+};
34
35
+// another
36
37
/**
38
* @param {number[]} nums
39
* @param {number} k
0 commit comments