C++ Solution


  • 0
    M
    class Solution {
    public:
        bool hasAlternatingBits(int n) {
            int check = 0;
            
            while(n) {
                check = n & 3;
                
                if (check == 1 || check == 2)
                    n >>= 2;
                else
                    return false;
            }
            
            return true;
        }
    };
    

Log in to reply
 

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