**SIMPLE JAVA SOLUTION**


  • 0
    T
       int one = 0,zero=0;
            
               while(n>0) {
                   if((n&1)==1){ one++;zero=0;}
                   else {zero++;one=0;}
                   if(one > 1 || zero > 1) return false;
                   n >>=1;
               }
            
               return true;
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.