[Java] Fast and Concise Java Solution (beats 100% solutions)


  • -1
    X
    class Solution {
        public boolean hasAlternatingBits(int n) {
            int m = n ^ (n >> 1);
            if ((m & (m + 1)) == 0)
                return true;
            else
                return false;
        }
    }
    

Log in to reply
 

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