Skip to content

Commit 593139f

Browse files
committed
Runtime: 216 ms (Top 89.74%) | Memory: 61.6 MB (Top 38.46%)
1 parent 74b837e commit 593139f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1+
// Runtime: 216 ms (Top 89.74%) | Memory: 61.6 MB (Top 38.46%)
12
var countPairs = function(deliciousness) {
23
const n = deliciousness.length;
34
const MOD = 1e9 + 7;
4-
5+
56
const map = new Map();
6-
7+
78
for (const num of deliciousness) {
89
if (!map.has(num)) map.set(num, 0);
910
map.set(num, map.get(num) + 1);
1011
}
11-
12-
let max = 2**21;
12+
13+
let max = 2**21;
1314
let res = 0;
14-
15+
1516
for (const [num, count] of map) {
1617

1718
let two = 1;
18-
19+
1920
while (two <= max) {
2021
const diff = two - num;
21-
22+
2223
if (diff >= 0 && map.has(diff)) {
23-
24+
2425
const otherCount = map.get(diff);
25-
26+
2627
if (num != diff) res += (count * otherCount);
2728
else res += (count * (count - 1) / 2);
2829
}
29-
30+
3031
two <<= 1;
3132
}
32-
33+
3334
map.delete(num);
3435
}
35-
36+
3637
return res % MOD;
37-
};
38+
};

0 commit comments

Comments
 (0)