Python Solution


  • 0
    P
    class Solution(object):
        def isOneBitCharacter(self, bits):
            """
            :type bits: List[int]
            :rtype: bool
            """
            # check if last bit is '0'
            n = len(bits)
            if bits[n-1] != 0:
                return False
            else:
                i = 0
                while i < n-2: # -1 for we have considered the last bit, another -1, we may use two bits at a time
                    print(bits[i], ', ')
                    if bits[i] == 1:
                        if bits[i+1] == 0 or bits[i+1] == 1:
                            i += 1
                        else:
                            return False
                    elif bits[i] == 0:
                        pass
                    i += 1
                if bits[i] == 1:
                    return False
                return True
                        
                    
    

Log in to reply
 

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