[LeetCode] Maximum Number That Makes Result of Bitwise AND Zero

3125. Maximum Number That Makes Result of Bitwise AND Zero

Given an integer n, return the maximum integer x such that x <= n, and the bitwise AND of all the numbers in the range [x, n] is 0.

1
2
3
4
5
6
class Solution {
public:
long long maxNumber(long long n) {
return (1ll<<((int)log2(n))) - 1;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2024/05/03/PS/LeetCode/maximum-number-that-makes-result-of-bitwise-and-zero/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.