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. 面向对象设计模式_享元模式(Flyweight Pattern)解读

      场景:程序需要不断创建大量相似的细粒度对象,会造成严重的内存负载.我们可以选择享元模式解决该问题. 享元抽象:Flyweight 描述享元的抽象结构.它包含内蕴和外蕴部分(别被术语迷惑,这是一种比较深 ...

    2. 排序算法(9)--Distribution Sorting--分布排序[1]--Counting sort--计数器排序

      1.基本思想 假设数序列中小于元素a的个数为n,则直接把a放到第n+1个位置上.当存在几个相同的元素时要做适当的调整,因为不能把所有的元素放到同一个位置上.计数排序假设输入的元素都是0到k之间的整数. ...

    3. hibernate动态表名映射

      引自:http://blog.csdn.net/xvshu/article/details/39187779 最近的一个项目有一个需求,有N个考核单位,要对每个考核单位生成一张考核情况表,这样做的目的 ...

    4. Windows10设置

      按下Win+R键,输入gpedit.msc,打开组策略窗口

    5. 使用GitHub-Pages创建博客和图片上传问题解决

      title: 使用GitHub Pages创建博客和图片上传问题解决 date: 2017-10-22 20:44:11 tags: IT 技术 toc: true 搭建博客 博客的搭建过程完全参照小 ...

    6. Google Play内购测试

      Google Play内购测试 最近项目做海外版本,接入Google wallet支付后,测试验证比较繁琐,故记录一下. Google wallet支付方式接入完成后,需要按照如下步骤设置,才可以进行 ...

    7. React 组件 API

      React 组件 API 在本章节中我们将讨论 React 组件 API.我们将讲解以下7个方法: 设置状态:setState 替换状态:replaceState 设置属性:setProps 替换属性 ...

    8. visual studio 单元测试的认识

      单元测试(unit testing),对软件中的最小单元进行检查和验证,其一般验证对象是一个函数或者一个类. Team Test 是 Visual Studio 集成的单元测试框架,它支持: 测试方法 ...

    9. MySQL MTS复制: hitting slave_pending_jobs_size_max

      测试步骤: 从库停止复制:stop slave; 主库创建大表400万条记录. 开启从库复制:start slave; 监测从库error log持续输出: 2018-12-06T10:40:52.6 ...

    10. 远程桌面web连接

        我们可以利用web浏览器搭配远程桌面技术来连接远程计算机,这个功能被称为远程桌面web连接(Remote desktop web connection),要享有此功能,请先在网络上一台window ...