717. 1-bit and 2-bit Characters
We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).
Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Note:
- 1 <= len(bits) <= 1000.
- bits[i] is always 0 or 1.
思路:判断列表长度,当列表长度为1的时候返回True, 判断列表头,为1的时候可以移除列表头2位,为0的时候可以移除1位,持续这个过程,最后如果列表为空就是False。
1 | class Solution(object): |