accepted java solution!


  • 0
    T
    class Solution {
        public boolean isOneBitCharacter(int[] bits) {
            if(bits.length==1){
                return true;
            }
            if(bits.length==2&&bits[0]==0&&bits[1]==0){
                return true;
            }else if(bits.length==2){
                return false;
            }else if(bits[bits.length-1]==0&&bits[bits.length-2]==0){
                return true;
            }
            
            if(check(bits.length-1-2,bits)){
                return false;
            }
            
            return true;
        }
        
        boolean check(int index,int[] bits){
            if(index<0){
                return true;
            }
            
            if(bits[index]==0){
                if(check(index-1,bits)){
                    return true;
                }
            }
            
            if(index-1>=0 && ((bits[index-1]==1&&bits[index]==1) || (bits[index-1]==1&&bits[index]==0))){
                if(check(index-2,bits)){
                    return true;
                }
            }
            
            return false;
        }
    }
    
    

Log in to reply
 

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