717. 1-bit and 2-bit Characters
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
bool isOneBitCharacter(vector<int>& bits)
{
int sz=bits.size();
int i=;
while(i<sz-)
{
if(bits[i]==)
i+=;
else
i+=;
}
return i==sz-;
}
};
这个题,从前向后扫,只要当前位为1,则不用管下一位是啥,必然要构成2位,所以当前位为1时,直接跳至下下个位置。
只有当末尾0前面有个落单的1时,末尾才不能为单,此时扫描到那个1的时候,加上2,i变为了sz
当末尾0前面不为非规则数字,i 必然不会跳过最后的0,会指向那个0,即i==sz-1
717. 1-bit and 2-bit Characters的更多相关文章
- LeetCode 717. 1比特与2比特字符(1-bit and 2-bit Characters)
717. 1比特与2比特字符 LeetCode717. 1-bit and 2-bit Characters 题目描述 有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 ...
- 【Leetcode_easy】717. 1-bit and 2-bit Characters
problem 717. 1-bit and 2-bit Characters 题意:solution1: class Solution { public: bool isOneBitCharacte ...
- 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 ...
- [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 ...
- 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 ...
- 717. 1-bit and 2-bit Characters最后一位数是否为0
[抄题]: We have two special characters. The first character can be represented by one bit 0. The secon ...
- 717. 1-bit and 2-bit Characters@python
We have two special characters. The first character can be represented by one bit 0. The second char ...
- 【LeetCode】717. 1-bit and 2-bit Characters 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcod ...
- 【LEETCODE】52、数组分类,简单级别,题目:717,661,746,628,643,849
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
随机推荐
- C++思考
1.复杂类型的对象,被栈或者队列等机制进行操作时,需要重新写其拷贝构造函数等,而不能使用默认拷贝构造函数. 2.复杂数据类型的对象的打印,需要对运算符进行重载,或者调用其中定义的打印方法.
- 151. Reverse Words in a String (String)
思路: 本题考查的目的并不是使用字符串的函数.方法是两次reverse,先对每个单词先做一次翻转,然后对整个字符串做一次翻转. 需要注意的是去除extra space,并且对全space字符串.以及最 ...
- win静态库动态库
静态链接库: #include "..\lib.h" #pragma comment(lib,"..\\debug\\libTest.lib") //指定与静态 ...
- java 线程Thread 技术--方法演示生产与消费模式
利用wait 与notifyAll 方法进行演示生产与消费的模式的演示,我们两个线程负责生产,两个线程消费,只有生产了才能消费: 在effective Java 中有说过: 1. 在Java 中 ,使 ...
- LWP::UserAgent的用法
LWP::UserAgent是一个模拟用户浏览器的类,在使用的时候需要遵守以下几步: 1.引入模块 2.创建一个LWP::UserAgent的对象 3.设置这个对象的相关参数 4.创建HTTP::Re ...
- JQuery UI之Autocomplete(1)入门程序
1.Autocomplete的主要属性:source:即为指定智能提示下拉框中的数据来源,支持三种类型. Array,主要用于本地化数据提供,支持两种格式:字符串数组 [ "Choice1 ...
- git bash 基本命令
1.打开git bash界面后,进入某个目录下时时,可以使用cd 命令,cd时change directory的简写,表示改变目录,比如,想切换到某个盘符下,可以使用cd g:,则会进入到g盘路径下, ...
- HTML 转 PDF 之 wkhtmltopdf 工具精讲
术语定义 文档对象 “文档对象”是指PDF文档中的文档对象,共有三种类型的“文档对象”,他们分别是“页面对象”,“封面对象”和“目录对象”. 页面对象 “页面对象”是指以页面的形式在PDF文档中呈现的 ...
- BCH/BSV coin split troubleshooting
BCH/BSV coin split troubleshootingMark Lundeberg 2018 November 27ResourcesGuides:Locktime based spli ...
- vue 自定义组件directives
自定义指令:以v开头,如:v-mybind. 代码示例: <input v-mybind /> directives:{ mybind:{ bind:function (el) { el. ...