LeetCode练习12

LeetCode练习12_第1张图片

解题思路:这个题没考啥东西,就是考你对python语法的掌握程度,将列表从左到右进行判断,如果以1为左标取完数的话,只剩下0那么就是True,反之就是flase。(代码写的还是非常简洁的~) 

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

LeetCode练习12_第2张图片

你可能感兴趣的:(算法)