Python Hacks (very short)


  • 0
    def isOneBitCharacter(self, bits):
        for b in bits:
            del bits[:b]
        return not b
    

    Or:

    def isOneBitCharacter(self, bits):
        return not [b and bits.pop(0) | 1 for b in bits][-1]
    

    Or one a little less horrible:

    def isOneBitCharacter(self, bits):
        for i, bit in enumerate(bits):
            if bit:
                bits.pop(i + 1)
        return not bit

Log in to reply
 

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