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的更多相关文章

  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_easy】717. 1-bit and 2-bit Characters

    problem 717. 1-bit and 2-bit Characters 题意:solution1: class Solution { public: bool isOneBitCharacte ...

  3. 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 ...

  4. [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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

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

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

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

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

随机推荐

  1. bootloader新的理解

    1.对于bootloader这样的程序,作为板卡刚开始启动的部分,大致的顺序是一致的,大部分都是分为两个部分,一部分是汇编编写的,一部分是用c语言编写的.一般在汇编部分完成各种初始化的操作,比如关闭看 ...

  2. Python: 高阶函数与lambda表达式

    缘由: python语法简单一看就会,但用在实处,想因为少于实战,总感觉有些捉襟. 翻阅跟踪youtube_dl源码,看到filter()函数用法,及其中lambda表达式,感觉好有意思,就补下课,记 ...

  3. android项目安装报错:INSTALL_FAILED_CONFLICTING_PROVIDER

    这主要是由于调试的环境中已有一个同名的Provider存在. 解决方法是修改AndroidManifest.xml中的 <provider android:name="applockP ...

  4. Nginx 做代理服务器时浏览器加载大文件失败 ERR_CONTENT_LENGTH_MISMATCH 的解决方案

    此文章仅作为本人的笔记,文章转载自  http://blog.csdn.net/defonds/article/details/46042809 Nginx 做反向代理,后端是 tomcat,chro ...

  5. [Z]sql优化

    前言:平常写的SQL可能主要以实现查询出结果为主,但如果数据量一大,就会突出SQL查询语句优化的性能独特之处.一般的数据库设计都会建索引查询,这样较全盘扫描查询的确快了不少.下面总结下SQL查询语句的 ...

  6. SSH Secure File Transfer Client 无法登陆

    嘉之叹息 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATI ...

  7. 遇到返回键会退到页面的问题(window.location)

    我的需求是a全局列表页->b展示列表页->c新增页(编辑页)我从b展示列表页,通过编辑进入c编辑页,保存回到b展示列表页. 重,我的b展示列表页,返回要返回的其实是a全局列表页*使用rep ...

  8. VsCode基本使用

    迫于公司统一编辑器,初次接触VsCode,小白入门笔记 安装插件及其用途: 1. Bracket Pair Colorizer :对括号对进行着色,再也不会搞不清状况了. 2. Git History ...

  9. mysql 存储过程 与 循环

    mysql 操作同样有循环语句操作,三种标准循环模式:while, loop,repeat, 外加一种非标准循环:goto [在c或c#中貌似出现过类型循环但是一般不建议用!] 一般格式为:delim ...

  10. tomcat用虚拟目录方式发布项目

    conf/Catalina/localhost:指定项目的配置信息 1.添加:ROOT.xml 听见Context节点: <Context docBase="/usr/local/to ...