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. Selenium常用API的使用java语言之1-环境安装之Java

    (一)环境安装之Java 1.安装java 点击 JDK8下载,根据自己的平台,选择相应的版本进行下载. 小知识: Java环境分JDK和JRE ,JDK就是Java Development Kit. ...

  2. Tornado之Session实现

    Tornado框架中,默认执行Handler的get/post等方法之前默认会执行 initialize方法,所以可以通过自定义的方式使得所有请求在处理前执行操作 import tornado.iol ...

  3. Ubuntu 下python开发环境的搭建

    一.安装python3 ubuntu自身是安装python2的,例如在ubuntu 16.04中安装的就是python2.7.但我想在python3的环境下进行开发所以就要安装python3.但由于u ...

  4. 数据库学习之七--视图(View)

    一.定义 视图:指计算机数据库中的一个临时虚拟表,其内容由查询定义:同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在. 二.优点 1. 优点: a. ...

  5. jQuery多选和单选下拉框插件select.js

    一.插件描述 可通过参数设置多选或者单选,多选返回数组结果,单选返回字符串,如图: 下载地址:https://pan.baidu.com/s/1JjVoK89_ueVVpfSlMDJwUQ   提取码 ...

  6. RBF、GRNN 和 PNN 神经网络在Matlab中的用法

    一.RBF神经网络 RBF神经网络概述 径向基函数神经网络 与 BP 神经网络的区别在于训练过程--其参数初始化具有一定方法,并非随机,隐含层的末尾使用了径向基函数,它的输出经过加权和得到 LW2.1 ...

  7. 1829:【02NOIP提高组】自由落体

    #include<bits/stdc++.h> using namespace std; double h,s1,v,k,l; int n,ans; int main() { cin> ...

  8. Metaspace 之二--PermGen vs. Metaspace 运行时比较

    PermGen vs. Metaspace 运行时比较 为了更好地理解Metaspace内存空间的运行时行为, 将进行以下几种场景的测试: 使用JDK1.7运行Java程序,监控并耗尽默认设定的85M ...

  9. Java 交换两数的方法

    错误示范 1. 直接交换 public class SwapNumbers { // 直接交换 public static void swap(int a, int b) { int temp = a ...

  10. jQuery Ajax calls and the Html.AntiForgeryToken()

    jQuery Ajax calls and the Html.AntiForgeryToken() https://stackoverflow.com/a/4074289/3782855 I use ...