Skip to content

Commit df308a8

Browse files
authored
Update 2275-largest-combination-with-bitwise-and-greater-than-zero.js
1 parent bf90139 commit df308a8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

2275-largest-combination-with-bitwise-and-greater-than-zero.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,29 @@ const largestCombination = function(candidates) {
1313
}
1414
return res
1515
};
16+
17+
// another
18+
19+
/**
20+
* @param {number[]} candidates
21+
* @return {number}
22+
*/
23+
const largestCombination = function(candidates) {
24+
const arr = Array(24).fill(0), len = 24
25+
for(const e of candidates) {
26+
const str = toBin(e)
27+
for(let n = str.length, i = n - 1; i >= 0; i--) {
28+
const cur = str[i]
29+
if(cur === '1') {
30+
arr[len - 1 - (n - 1 - i)]++
31+
}
32+
}
33+
}
34+
35+
return Math.max(...arr)
36+
37+
function toBin(num) {
38+
return (num >>> 0).toString(2)
39+
}
40+
};
41+

0 commit comments

Comments
 (0)