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. 不依赖AIDL的跨进程通信

      http://blog.csdn.net/lmj623565791/article/details/38461079 如果知道AIDL和binder的原理,可以简单写一个不依赖AIDL的跨进程通信 不 ...

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

      head命令 作用:显示文件的头部内容,默认显示前面10行 格式: head [option] [file] -n <行数> -c <字节> ghostwu@dev:~/lin ...

    3. Linux常用基本命令(more)

      more命令 作用:相比cat一次性显示文件内容,more用于分页显示内容,less比more更强大,大多数的参数类似 more [option] [file] -num : 每页显示num行 +nu ...

    4. linux系统编程:自己动手写一个cp命令

      cp命令的基本用法: cp 源文件 目标文件 如果目标文件不存在 就创建, 如果存在就覆盖 实现一个cp命令其实就是读写文件的操作: 对于源文件: 把内容全部读取到缓存中,用到的函数read 对于目标 ...

    5. 老男孩教育python全栈第九期视频

      失效了在下面评论即可,会及时更新.python9期已全部更新完 链接: https://pan.baidu.com/s/1VV8_ZyVasK05iKd7QMxO-A 密码: 9zau

    6. 【代码笔记】iOS-HTTPQueue下载图片

      一,工程图. 二,代码. ViewController.h #import <UIKit/UIKit.h> #import "ASIHTTPRequest.h" #im ...

    7. MonkeyRunner进坑——errors importing other modules

      后知后觉,刚知道Android提供了MonkeyRunner这么个东西,能用来干嘛呢,官方文档介绍得很清楚.简单说,可以用Python程序通过API, installs an Android appl ...

    8. 护网杯 task_shoppingCart 记录

      前言 相关题目位于 https://gitee.com/hac425/blog_data/tree/master/hwb task_shoppingCart 漏洞位于 00BD9 用户输入 idx 然 ...

    9. redis学习历程

      redis只知道作用于缓存,其它一无所知,所以现在系统的 学习下,这样应用的时候可以考虑多面性和实用性 首先先了解一下redis的背景和概念 背景 Redis是一个开源的使用ANSI C语言编写.支持 ...

    10. CSS揭秘(一)引言

      借了一本CSS揭秘,国外的一本书,应该是目前相关书目里最好的了,内容非常扎实,不得不说图灵教育出的书真的不错,不然不是很厚的一本书卖到99也是.... 国外的这类书总是以问题开始,然后通过解决问题引出 ...