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 * ...
随机推荐
- Vue之数据监听存在的问题
Vue之数据监听 当数据监听的是列表时,数据发生改变,不会被监听到. // 用$set修改数组中的数组能够被监听 // app.$set(this.hobby, 0, "爱你哦") ...
- Netty实践一(数据通信)
我们需要了解下在真正项目应用中如何去考虑Netty的使用,大体上对于一些参数设置都是根据服务器性能决定的.这个不是最主要的. 我们需要考虑的问题是两台机器(甚至多台)使用Netty的怎样进行通信,大体 ...
- vue 返回上一页后,上一页由参数渲染的内容无法显示
思路1:将参数传递给第二个页面后,返回上一页时,再讲参数传回第一页(此方法适用于层级少的)(亲测有效) 思路2:将参数放到全局变量中(还未尝试过)
- TZOJ 2546 Electricity(去掉割点后形成的最大连通图数)
描述 Blackouts and Dark Nights (also known as ACM++) is a company that provides electricity. The compa ...
- django具体操作(七)
新增组件 使用 python manage.py startapp新建一个app,并且在settings中注册,添加stark.apps.StarkConfig, 然后在stark的apps中添加re ...
- 动态替换iframe的src及动态改变iframe的高度
实现效果:点击左侧右侧内容变化,但左侧保持不变(如折叠等) 动态替换iframe的src <iframe width="100%" frameBorder="0&q ...
- Windows系统制作Ubuntu启动U盘(命令行)
背景 现今Ubuntu系统的使用越来越多,考虑到日常办公还是用Windows系统,但开发的需求常常要有Linux系统.因此将Linux系统安装到U盘不失为一种好的选择.在Windows系统上制作Ubu ...
- eclipse 安装python后pydev不出现
一.环境 windows 7 64bit eclipse 4.5.2 pydev jdk7u55 二.安装步骤 1. 安装JDK eclipse依赖于java环境,所以需要安装java运行环境JRE. ...
- Excel上传找到错误数据类型
一:查询数据库表中字段的类型语句 SELECT CASE WHEN col.colorder = 1 THEN obj.name ELSE '' END AS 表名, col.colorder AS ...
- python3.5.2中文字符乱码问题解决
>>> str = "世界你好!" >>> b = str.encode('utf-8') >>> type(b) <c ...