[LeetCode] 717. 1-bit and 2-bit Characters_Easy
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 always0or1.
这个题目思路因为如果为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的更多相关文章
- LeetCode 717. 1比特与2比特字符(1-bit and 2-bit Characters)
717. 1比特与2比特字符 LeetCode717. 1-bit and 2-bit Characters 题目描述 有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 ...
- 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 ...
- Java实现 LeetCode 717 1比特与2比特字符(暴力)
717. 1比特与2比特字符 有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 11)来表示. 现给一个由若干比特组成的字符串.问最后一个字符是否必定为一个一比特字符. ...
- 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 ...
- [LeetCode] All questions numbers conclusion 所有题目题号
Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...
- C#版[击败98.85%的提交] - Leetcode717. 1比特与2比特字符 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- 【LEETCODE】52、数组分类,简单级别,题目:717,661,746,628,643,849
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 【LeetCode】717. 1-bit and 2-bit Characters 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcod ...
- [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 ...
随机推荐
- SQL Server设置登录验证模式
我们在安装SQL Server的时候可以设置“混合验证模式”,既可以使用windows身份验证登录,也可以使用SQL Server身份验证登录. 如果我们在安装的时候并未设置"混合验证模式& ...
- Python pyQt4/PyQt5 学习笔记3(绝对对位,盒布局,网格布局)
本节研究布局管理的内容. (一)绝对对位 import sys from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__( ...
- sencha touch 在线实战培训 第一期 第二节
2013.12.30晚上8点开的课,仍然有些紧张,开始讲课进度很慢,后面又有些快了... 本期培训一共八节,前三堂免费,后面的课程需要付费才可以观看. 本节内容: 页面实现及跳转控制 跳转容器.路由理 ...
- Logstash自带正则表达式
USERNAME [a-zA-Z0-._-]+ USER %{USERNAME} INT (?:[+-]?(?:[-]+)) BASE10NUM (?<![-.+-])(?>[+-]?(? ...
- POJ-1179 Polygon (动态规划)
Polygon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5293 Accepted: 2238 Description P ...
- TOP100summit:【分享实录】Twitter 新一代实时计算平台Heron
本篇文章内容来自2016年TOP100summit Twitter technical lead for Heron Maosong Fu 的案例分享. 编辑:Cynthia Maosong Fu:T ...
- 反正切函数atan与atan2的区别
atan 和 atan2 都是求反正切函数,如:有两个点 point(x1,y1), 和 point(x2,y2); 那么这两个点形成的斜率的角度计算方法分别是: float angle = atan ...
- ubuntu16.04下安装kdevelop和汉化
1.Kdevelop安装 最简单的命令行安装,打开终端,执行 sudo apt-get install kdevelop 2.Kdevelop汉化 不需要自己下载汉化包,Kdevelop安装后,在终端 ...
- slam学习资源
从零开始学slam: http://blog.csdn.net/akunainiannian/article/details/45363731 史上最全的SLAM学习资料收集 http://www. ...
- codeforces 355C - Vasya and Robot
因为在允许的情况下,必然是左右手交替进行,这样不会增加多余的无谓的能量. 然后根据不同的分界点,肯定会产生左手或右手重复使用的情况,这是就要加上Qr/Ql * 次数. 一开始的想法,很直接,枚举每个分 ...