Skip to content

Latest commit

 

History

History
14 lines (12 loc) · 190 Bytes

693. Binary Number with Alternating Bits.md

File metadata and controls

14 lines (12 loc) · 190 Bytes
class Solution {
public:
    bool hasAlternatingBits(int n) {
        n = n ^ (n >> 2);
        return (n & (n - 1)) == 0;
    }
};

//    000101010
//  ^ 000001010
//  = 000100000