Coding Made Dizzy
To code, or not to code, that is the question
Saturday, October 7, 2017
693. Binary Number with Alternating Bits
bool hasAlternatingBits(int n) {
if(n&1) n >>= 1;
int i=0;
while(n){
if((n&3) != 2) return false;
n >>= 2;
}
return true;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment