Binary Number with Alternating Bits

给一个数字n, 问n的二进制是不是0和1交替的.

class Solution {
    public boolean hasAlternatingBits(int n) {
        int cur = n % 2;
        n /= 2;
        while (n > 0) {
            if (cur == n % 2) 
                return false;
            cur = n % 2;
            n /= 2;
        }
        return true;
    }
}