717. 1-bit and 2-bit Characters@python
2021-06-16 06:02
标签:represent rip problem can spec 思路 elf etc lis We have two special characters. The first character can be represented by one bit 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-bit and 2-bit Characters 难度: Easy 题意: 存在两类数,一类是10或者11,另一类为0.将一个数组拆分为这两类数,判断最后一组数为0,比如上面例子,第一组数为[1,0],第二组数为[0] 思路: 对于数字1,后面的一个数字是1或者0都行,所以遇到以可以跳过1后面的值,遇到0,则移动一位 代码: 时间复杂度: O(n) 空间复杂度: O(1) 717. 1-bit and 2-bit Characters@python 标签:represent rip problem can spec 思路 elf etc lis 原文地址:https://www.cnblogs.com/chimpan/p/9727047.html0
. The second character can be represented by two bits (10
or 11
).Input:
bits = [1, 0, 0]
Output: True
Explanation:
The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.
class Solution(object):
def isOneBitCharacter(self, bits):
"""
:type bits: List[int]
:rtype: bool
"""
i = 0
while i len(bits):
if bits[i] == 1:
i += 2
if i == len(bits):
return False
else:
i += 1
return True
上一篇:关于Delphi内存表的使用说明
下一篇:从语言只是工具说起
文章标题:717. 1-bit and 2-bit Characters@python
文章链接:http://soscw.com/essay/94453.html