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. HDU-1042.N!(大数与小数相乘的乘法模拟)

    本题大意:给定一个10000以内的整数n,让你求出n!并输出. 本题思路:先初始化一个存放答案的数组ans,初始ans[0] = 1,并初始化其剩下的元素为0,接着就从2开始依次与ans数组内的每一个 ...

  2. 总结函数open与fopen的区别

    转自:https://www.zybuluo.com/yiltoncent/note/87461 对于这两个名字很类似的函数,对于很多初学者来说,不容易搞清楚它们有什么不同,只知道按照函数用法使用.如 ...

  3. 解决com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭

    com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭. at com.microsoft.sqlserver.jdbc.SQLServerEx ...

  4. echarts横向柱状图如果想打开网址

    代码: var data = eval(data); var xList = new Array(); var yList = new Array(); var urlList = new Array ...

  5. Tomcat登陆mysql的密码设置

    在登陆mysql的密码和数据库密码不一致时,可以修改Mysql数据库密码或者修改连接Mysql的配置文件:  1.修改连接Tomcat里连接Mysql的配置文件 需要修改两个配置文件 ,一个是在tom ...

  6. webpack.dev.conf.js

    var utils = require('./utils')var webpack = require('webpack')var config = require('../config') // 一 ...

  7. Django中使用django_debug_toolbar

    一 概述 django_debug_toolbar 是django的第三方工具包,给django扩展了调试功能. 包括查看执行的sql语句,db查询次数,request,headers,调试概览等. ...

  8. jquery ajax 中实现给变量赋值

    我们在用JQuery的Ajax从后台提取数据后想把它赋值给全局变量,但是却怎么都赋不进,为什么呢? 原因其实很简单,我们用的Ajax是异步操作,也就是说在你赋值的时候数据还没提取出来,你当然赋不进去, ...

  9. c#task list waitall task waitany

    上边的主线程会被卡住: 7个同时开发,谁先完成之后, 需要完成某个工作,可以用waitany 2: 不卡界面的做法 加上以上命令就不卡,是子线程做的事 //Task task = taskFactor ...

  10. andorid 多线程handler用法

    .xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...