leetcode和算法----日更

leetcode 717 1比特与2比特字符

2020-02-19  本文已影响0人  Arsenal4ever

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

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       
上一篇 下一篇

猜你喜欢

热点阅读