717. 1-bit and 2-bit Characters

題目地址:https://leetcode.com/problems/1-bit-and-2-bit-characters/description/

大意:給定一串序列由01構成,其中構成的子序列可以是01011三種,看最後一個子序列是否是0

思路:由於只有一個長度爲1的子序列,就是需要判斷的值,就由第一個字符判斷長度就行了。

class Solution:
    def isOneBitCharacter(self, bits):
        """
        :type bits: List[int]
        :rtype: bool
        """
        length = len(bits)
        dot = 0
        while dot < length:
            if dot == length -1:
                return True
            if bits[dot] == 0:
                dot += 1
            else:
                dot += 2    
        return False




所有題目解題方法和答案代碼地址:https://github.com/fredfeng0326/LeetCode
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章