C++ 2line


  • 0
    M
    class Solution {
    public:
        bool hasAlternatingBits(int n) {
            long long m = n >> 1;
            return ((m + n) & (m + n + 1)) == 0;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.