美文网首页leetcode和算法----日更
leetcode 717 1比特与2比特字符

leetcode 717 1比特与2比特字符

作者: Arsenal4ever | 来源:发表于2020-02-19 23:27 被阅读0次

状态机,画出来最好,除了要把各个情况考虑全外,还要考虑先后判断顺序

class Solution(object):
    def isOneBitCharacter(self, bits):
        """
        :type bits: List[int]
        :rtype: bool
        """
        secondSign = False
        answer = False
        for i in range(len(bits)):
            if secondSign == False and bits[i] == 1:
                answer = False
                secondSign = True
            elif secondSign == False and bits[i] == 0:
                answer = True
                secondSign = False
            elif secondSign == True:
                secondSign = False
                answer = False
            else:
                continue
        return answer       

相关文章

网友评论

    本文标题:leetcode 717 1比特与2比特字符

    本文链接:https://www.haomeiwen.com/subject/mdxtqhtx.html