Leetcode【111】1-bit and 2-bit Characters(Python)版

class Solution(object):
    def isOneBitCharacter(self, bits):
        """
        :type bits: List[int]
        :rtype: bool
        """
        i = 0
        while i < len(bits) - 1:
            i += bits[i] + 1
        return i == len(bits) - 1

如果bits[i] = 0那么i向前移动一位,如果bits[i] = 1那么i向前移动两位

如果跳出循环之前bits[i] = 0,那么最后i+1后一定等于数组的长度-1

如果跳出循环之前bits[i] = 1,那么最后i+2后一定等于数组长度

发布了233 篇原创文章 · 获赞 85 · 访问量 153万+

猜你喜欢

转载自blog.csdn.net/ssjdoudou/article/details/104187815
BIT
今日推荐