717. 1 比特与 2 比特字符
为保证权益,题目请参考 717. 1 比特与 2 比特字符(From LeetCode).
解决方案1
Python
python
# 717. 1比特与2比特字符
# https://leetcode-cn.com/problems/1-bit-and-2-bit-characters/
from typing import List
class Solution:
def isOneBitCharacter(self, bits: List[int]) -> bool:
last_bit = -1
idx = 0
while idx < len(bits):
if bits[idx] == 0:
idx += 1
last_bit = 1
else:
idx += 2
last_bit = 2
if last_bit == 1:
return True
else:
return False
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23