Binary Number with Alternating Bits LeetCode solution in C++

1
class Solution {
2
public:
3
const static uint32_t a = 0b10101010101010101010101010101010;
4
bool hasAlternatingBits(int n) {
5
return ((a >> __builtin_clz(n)) ^ n) == 0;
6
}
7
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0