We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).

Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero.

Example 1:

Input:
bits = [1, 0, 0]
Output: True
Explanation:
The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character.

Example 2:

Input:
bits = [1, 1, 1, 0]
Output: False
Explanation:
The only way to decode it is two-bit character and two-bit character. So the last character is NOT one-bit character.

Note:

  • 1 <= len(bits) <= 1000.

  • bits[i] is always 0 or 1.
  • 想法:遍历vector,遇到1,指针加2,遇到0,指针加1,判断指针和数组最后一位是否相等。

    class Solution {
    public:
        bool isOneBitCharacter(vector<int>& bits) {
            int len = bits.size();
            ;;
            ){
                )
                    index +=;
                else
                    index++;
    
            }
            ;
        }
    };

    leetcode717—1-bit and 2-bit Characters的更多相关文章

    1. [Swift]LeetCode717. 1比特与2比特字符 | 1-bit and 2-bit Characters

      We have two special characters. The first character can be represented by one bit 0. The second char ...

    2. C#版[击败98.85%的提交] - Leetcode717. 1比特与2比特字符 - 题解

      版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

    3. LeetCode 717. 1比特与2比特字符(1-bit and 2-bit Characters)

      717. 1比特与2比特字符 LeetCode717. 1-bit and 2-bit Characters 题目描述 有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 ...

    4. LeetCode[3] Longest Substring Without Repeating Characters

      题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

    5. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

      Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

    6. [LeetCode] Sort Characters By Frequency 根据字符出现频率排序

      Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...

    7. [LeetCode] Longest Substring with At Most K Distinct Characters 最多有K个不同字符的最长子串

      Given a string, find the length of the longest substring T that contains at most k distinct characte ...

    8. [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串

      Given a string S, find the length of the longest substring T that contains at most two distinct char ...

    9. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

      The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

    随机推荐

    1. 桥接模式(Bridge)

      1.概念 桥接模式将抽象部分与它的实现部分分离,使它们都可以独立地变化,属于结构性模式的一种. 2.模式结构 Abstraction(抽象类):定义抽象接口,拥有一个Implementor类型的对象引 ...

    2. Linux常用基本命令(xargs )

      xargs:能够将管道或者标准输入传递的数据转换成xargs命令后面跟随的参数 ghostwu@dev:~/linux/cp$ ls ghostwu_hardlink ghostwu_home gho ...

    3. Python 初识网络

      一. C/S架构:客户端(client)/服务端(server)架构 B/S架构:浏览器(browser) / 服务端(server)架构 软件cs架构: 浏览器,qq,微信等等 硬件cs架构:打印机 ...

    4. 【查找数字x第k为上的数字】

      #include<stdio.h> #include<math.h> // 求x用10进制表示时的数位长度 int len(int x){ ) ; )+; } // 取x的第k ...

    5. <Android 应用 之路> JuheNews For aNdroid (改进版)

      简介 最新版应用已经上线,欢迎下载使用,提出宝贵意见: http://shouji.baidu.com/software/10720907.html 上一篇介绍的是最开始自己制作的一个采用聚合数据免费 ...

    6. [可能不知道]什么是PeopleSoft的JOLT以及相关进程

      PeopleSoft applecation server依赖于Jolt,Jolt是与Tuxedo配套的产品,可以处理所有web请求.换句话说,Jolt是application server与web ...

    7. jQuery首页更换背景皮肤

      昨天做了一个jQuery首页更换背景皮肤,感觉还是挺不错的,一共需要两个文件,一个是我们写的HTML文件,我们起名叫做index.html,一个是我们引入的jQuery文件,我们起名叫做jQuery. ...

    8. SQLServer 学习笔记之超详细基础SQL语句 Part 7

      Sqlserver 学习笔记 by:授客 QQ:1033553122 -----------------------接Part 6------------------- 29 存储过程和触发器 存储过 ...

    9. CentOS 7下安装Python3.5

      CentOS 7下安装Python3.5 •安装python3.5可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-deve ...

    10. Python Django框架笔记(四):数据分页和CSRF跨站点请求伪造

      (一)数据分页  可以参考  https://docs.djangoproject.com/en/2.0/topics/pagination/ 模板:如果只要显示 1.2.3.4.5.6....的话, ...