Check set or not on every other bit


  • 0
    L
    public class Solution {
        public boolean isPowerOfFour(int num) {
            return (num > 0) && (num & (num-1)) == 0 && (num & (0x2AAAAAAA)) == 0;
        }
    }

Log in to reply
 

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