描述
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
.
分析
输入是一个数组,其中的元素是 10,11, 0,判断最后一个元素是否为 0。注意到 0 长度是1,10,11 的长度都是2,一次遍历即可。时间复杂度为 O(n), 空间复杂度为 O(n)
解决方案1(Java)
1 | class Solution { |