标签:shift leetcode asa unshift 练习 style i++ lte ++
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]){ return false; } } return true; };
leetcode练习:693. Binary Number with Alternating Bits
标签:shift leetcode asa unshift 练习 style i++ lte ++
原文地址:http://www.cnblogs.com/rimochiko/p/7738546.html