problem

717. 1-bit and 2-bit Characters

题意:
solution1:

class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
int i=;
while(i<bits.size()-)
{
if(bits[i]==) i+=;
else i+=;
}
return i==bits.size()-;
}
};

solution2:根据数组的特性计算。

class Solution {
public:
bool isOneBitCharacter(vector<int>& bits) {
int i=, n = bits.size();
while(i<n-)
{
//if(bits[i]==0) i+=1;
//else i+=2;
i += bits[i]+;
}
return i==n-;
}
};

参考

1. Leetcode_easy_717. 1-bit and 2-bit Characters;

2. Grandyang;

【Leetcode_easy】717. 1-bit and 2-bit Characters的更多相关文章

  1. 【Leetcode_easy】1021. Remove Outermost Parentheses

    problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完

  2. 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers

    problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...

  3. 【Leetcode_easy】1025. Divisor Game

    problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完

  4. 【Leetcode_easy】1029. Two City Scheduling

    problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完

  5. 【Leetcode_easy】1030. Matrix Cells in Distance Order

    problem 1030. Matrix Cells in Distance Order 参考 1. Leetcode_easy_1030. Matrix Cells in Distance Orde ...

  6. 【Leetcode_easy】1033. Moving Stones Until Consecutive

    problem 1033. Moving Stones Until Consecutive 参考 1. Leetcode_easy_1033. Moving Stones Until Consecut ...

  7. 【Leetcode_easy】1037. Valid Boomerang

    problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完

  8. 【Leetcode_easy】1042. Flower Planting With No Adjacent

    problem 1042. Flower Planting With No Adjacent 参考 1. Leetcode_easy_1042. Flower Planting With No Adj ...

  9. 【Leetcode_easy】1046. Last Stone Weight

    problem 1046. Last Stone Weight 参考 1. Leetcode_easy_1046. Last Stone Weight; 完

随机推荐

  1. xld特征

    halcon中什么是xld? xld(eXtended Line Descriptions) 扩展的线性描述,它不是基于像素的,人们称它是亚像素,只不过比像素更精确罢了,可以精确到像素内部的一种描述. ...

  2. vue2 单一事件中心管理组件通信

  3. JavaScript 常用Object

    对象 - Map 功能:Map 对象保存键值对. 方法: new Map():新建一个 Map 对象 Map.prototype.has(key):返回布尔值.表示 Map 实例是否包含键对应的值. ...

  4. QQ龙虎榜数据接口

    1.个股全部上榜日期 strUrl.Format(L"http://stock.finance.qq.com/cgi-bin/sstock/q_lhb_js?t=1&c=%06d&q ...

  5. NuGet本地包自定义路径

    <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSo ...

  6. MongoDB 分片管理(四)数据均衡 -- 特大快

    1.1 特大快形成 如果用date字段作为片键,集合中date是一个日期字符串,如:year/month/day,也就是说,mongoDB一天创建一个块.因块内所有文档的片键一样,因此这些块是不可拆分 ...

  7. 2019ICPC南京自我反省

    第一场ICPC,跟第一场CCPC一样,可惜真的可惜. 打完比赛就感觉难受,难受不在于又抱了块铜牌,而是那种能出的题没出的可惜感非常浓重. 开场还是可以的,通过一阵讨论,就大胆猜测了A的规律,然后一发过 ...

  8. Spring Cloud Gateway(九):网关过滤器 GatewayFilter

    本文基于 spring cloud gateway 2.0.1 1.简介 GatewayFilter 网关过滤器用于拦截并链式处理web请求,可以实现横切的与应用无关的需求,比如:安全.访问超时的设置 ...

  9. Java核心复习—— ThreadLocal源码分析

    ThreadLocal,叫做线程本地存储,也可以叫做线程本地变量.ThreadLocal为变量在每个线程中都创建了一个副本,那么每个线程可以访问自己内部的副本变量. 一.如何使用 class Acce ...

  10. Mac下不能成功打开uiautomatorviewer的问题解决

    在终端运行uiautomatorviewer之后出现下面的错误,检查以后发现环境变量也配置好了 Error: Could not create the Java Virtual Machine. Er ...