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.

这个题目思路因为如果为1的话后面接下来的bit就没用, 所以往后跳两格, 如果是0, 跳一格, 最后如果指在最后一个元素, 那么肯定是要一个元素单独, 否则就是可以不单独.

Code

class Solution:
def 12bits(self, bits):
i, length = 0, len(bits) -1
while i < length:
i += bits[i] + 1
return i == length

[LeetCode] 717. 1-bit and 2-bit Characters_Easy的更多相关文章

  1. LeetCode 717. 1比特与2比特字符(1-bit and 2-bit Characters)

    717. 1比特与2比特字符 LeetCode717. 1-bit and 2-bit Characters 题目描述 有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 ...

  2. leetcode 717. 1-bit and 2-bit Characters -easy

    https://leetcode.com/problems/1-bit-and-2-bit-characters/description/ We have two special characters ...

  3. Java实现 LeetCode 717 1比特与2比特字符(暴力)

    717. 1比特与2比特字符 有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 11)来表示. 现给一个由若干比特组成的字符串.问最后一个字符是否必定为一个一比特字符. ...

  4. LeetCode 717. 1-bit and 2-bit Characters

    We have two special characters. The first character can be represented by one bit 0. The second char ...

  5. [LeetCode] All questions numbers conclusion 所有题目题号

    Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...

  6. C#版[击败98.85%的提交] - Leetcode717. 1比特与2比特字符 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  7. 【LEETCODE】52、数组分类,简单级别,题目:717,661,746,628,643,849

    package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...

  8. 【LeetCode】717. 1-bit and 2-bit Characters 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcod ...

  9. [LeetCode&Python] Problem 717. 1-bit and 2-bit Characters

    We have two special characters. The first character can be represented by one bit 0. The second char ...

随机推荐

  1. springbatch---->springbatch的使用(三)

    这里我们对上篇博客的例子做一个修改性的测试来学习一下springbatch的一些关于chunk的一些有用的特性.我渐渐能意会到,深刻并不等于接近事实. springbatch的学习 一.chunk的s ...

  2. jQuery队列(一)

    jQuery的队列依赖缓存机制事件,它同时是animate的基础. 它不像事件机制.缓存机制.回调机制一样有自己的命名空间,由于比较简单,所以直接挂在到$和jQuery对象上. 它提供的基础方法有: ...

  3. [Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually

    7down voteaccepted I don't think its necessary to add everything into path.Just add the JAVA_HOME , ...

  4. 源码包安装Python3.6

    1,安装Python3.6的依赖包 # yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel r ...

  5. Linux下openoffice与SWFtools的安装

    第一部份:OpenOffice的安装 1.Openoffice的官网:http://www.openoffice.org/download/index.html 选择Linux 64-bit(x860 ...

  6. python nose测试框架全面介绍四

    四.内部插件介绍 1.Attrib 标记,用于筛选用例 在很多时候,用例可以分不同的等级来运行,在nose中很增加了这个功能,使用attrib将用例进行划分 有两种方式: ef test_big_do ...

  7. Unity3D笔记 GUI 四、实现选项卡三

    一.代码: using UnityEngine; using System.Collections; /// <summary> /// 选项卡二 /// </summary> ...

  8. RabbitMQ 安装和说明

    一.安装 1. 下载源码,RabbitMQ是使用Erlang开发,所以安装RabbitMQ前需要先安装Erlang.官方推荐从源码安装Erlang,因此下面开始从源码安装OTP 17.0.下载OTP ...

  9. 编程(Linux、windows)常见命令

    1.history | grep  start 可以查看该linux上输入过的包含start的所有命令 2. for /r %i in (*.lastUpdated) do del %i 在windo ...

  10. [转]-[携程]-A Hybrid Collaborative Filtering Model with Deep Structure for Recommender Systems

    原文链接:推荐系统中基于深度学习的混合协同过滤模型 近些年,深度学习在语音识别.图像处理.自然语言处理等领域都取得了很大的突破与成就.相对来说,深度学习在推荐系统领域的研究与应用还处于早期阶段. 携程 ...