leetcode练习:693. Binary Number with Alternating Bits
693是一道很简单的题目。
var hasAlternatingBits = function(n) {
var bin = [];
while(n>0){
bin.unshift(n%2);
n = parseInt(n/2);
}
bin.join('');
var len = bin.length;
var i,j;
for(i = 0;i<len ;i++){
if(bin[i] == bin[i+1]){
returnfalse;
}
}
returntrue;
};