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:

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.

Example 2:

Input:
bits = [1, 1, 1, 0]
Output: False
Explanation:
The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.

Note:

  • 1 <= len(bits) <= 1000.
  • bits[i] is always 0 or 1.

class Solution(object):
def isOneBitCharacter(self, bits):
"""
:type bits: List[int]
:rtype: bool
"""
i=0
while i<len(bits)-1:
i+=bits[i]+1
return i==len(bits)-1

  

[LeetCode&Python] Problem 717. 1-bit and 2-bit Characters的更多相关文章

  1. [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...

  2. [LeetCode&Python] Problem 387. First Unique Character in a String

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  3. [LeetCode&Python] Problem 427. Construct Quad Tree

    We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or ...

  4. [LeetCode&Python] Problem 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  5. [LeetCode&Python] Problem 520. Detect Capital

    Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...

  6. [LeetCode&Python] Problem 226. Invert Binary Tree

    Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Tr ...

  7. [LeetCode&Python] Problem 905: Sort Array By Parity

    Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...

  8. [LeetCode&Python] Problem 1: Two Sum

    Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...

  9. [LeetCode&Python] Problem 682. Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

随机推荐

  1. C++手机通讯录排序

    参考:https://www.cnblogs.com/lhwblog/p/6486036.html Qt 4.8.4 vs2008 #include <QtGui/QApplication> ...

  2. Mybatis排序无效问题解决

    在 mybatis 的 xml中,为一个SQL语句配置order by 子句时,需要这个排序的字段是前端传递过来的,而且排序的顺序(升序 OR 降序)也是由前端传递过来的.对于这种需求,我起初写成了下 ...

  3. python(2)之列表

    列表的使用 names=["zhangyang","liming",["sese","popo"],"xiao ...

  4. linux下top命令参数详解

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法. 内存信息.内容如下: Mem: 191272k to ...

  5. linux系统监控与硬盘分区/格式化/文件系统管理

    1.系统监控 1) 系统监视和进程控制的工具----> Top 与  free      类似于windows的资源管理器.     进程运行的三种状态: tips: 进程(Process)是计 ...

  6. pyhton-函数初级

    f = open("司马光砸缸", mode="r+", encoding="utf-8") f.seek(12) f.truncate() ...

  7. 初学Linux系统最应该做对的4件事情[长文]

    “闲来无事,逛逛贴吧”已经是本人无事消磨时间的最佳选择了.五花八门的问题,各式各样的回答,总能给自己带来无限的欢乐.当然也有些问题值得自己去思考或者回答.之前就有人在贴吧里问到“Linux好难啊!该怎 ...

  8. java①

    1.MyEclipse Eclipse Idea 等 都是 开发java的IDE工具! 2.面试题: JDK: java开发工具包!(Java Development TooKit)! 是整个java ...

  9. vue-7-表单

    示例: <input v-model="message" placeholder="edit me"> <p>Message is: { ...

  10. set的三种遍历方式-----不能用for循环遍历(无序)

    set的三种遍历方式,set遍历元素 list 遍历元素 http://blog.csdn.net/sunrainamazing/article/details/71577662 set遍历元素 ht ...