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. Java - "JUC"之Condition源码解析

      Java多线程系列--“JUC锁”06之 Condition条件 概要 前面对JUC包中的锁的原理进行了介绍,本章会JUC中对与锁经常配合使用的Condition进行介绍,内容包括:Condition ...

    2. systemd管理服务

      [root@zbs-staging-api system]# cat /lib/systemd/system/ncmulti@.service [Unit] Description=many on % ...

    3. css中计数器的实现-笔记

      原文参考http://mp.weixin.qq.com/s?__biz=MzU3MDA0NTMzMA==&mid=2247485533&idx=1&sn=e88dc5fffa6 ...

    4. CentOS7+ApacheServer2.4+MariaDB10.0+PHP7.0+禅道项目管理软件8.0环境部署

      CentOS7+ApacheServer2.4+MariaDB10.0+PHP7.0+禅道项目管理软件8.0环境部署 by:授客 QQ:1033553122 目录 一. 二. 三. 四. 五. 六. ...

    5. 8 张脑图入门 JavaScript - 基础面试不倒

      8 张脑图入门 JavaScript - 基础面试不倒 转载请注明出处 第一:JavaScript 的变量 第二:JavaScript 运算符 第三:JavaScript 数组 第四:JavaScri ...

    6. RecyclerView 下拉刷新和加载更多

      一.SwipeRefreshLayout实现下拉刷新 1.方法API: setOnRefreshListener(OnRefreshListener):添加下拉刷新监听器 setRefreshing( ...

    7. Intellij IDEA去除@Autowired下划线红色提示

      Intellij IDEA通过@Autowired注入的对象,在不改变配置的情况下一直有红色下划线,虽然不影响运行,但是跟小Alan一样有强迫症的肯定受不鸟. 那么怎么去除它呢? 解决方式:改变@Au ...

    8. ASP.NET Core Razor生成Html静态文件

      一.前言 最近做项目的时候,使用Util进行开发,使用Razor写前端页面.初次使用感觉还是不大习惯,之前都是前后端分离的方式开发的,但是使用Util封装后的Angular后,感觉开发效率还是杠杠滴. ...

    9. NewEmployeesLearnNotes——新人程序员学习计划V1.1

      百度云链接:https://pan.baidu.com/s/1BzoT79tV1QGwIQTjkGA4CQ 密码:k78i 修改中...

    10. 全面认识一下.NET 4.0的缓存功能 (转)

      转自:http://www.cnblogs.com/hjf1223/archive/2010/07/16/net_4_caching.html 很多关于.NET 4.0新特性的介绍,缓存功能的增强肯定 ...