状态机,画出来最好,除了要把各个情况考虑全外,还要考虑先后判断顺序
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
网友评论