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. 大明A+B(hdu1753)大数,java

      大明A+B Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

    2. Code Signal_练习题_Knapsack Light

      You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

    3. BZOJ2208: [Jsoi2010]连通数(tarjan bitset floyd)

      题意 题目链接 Sol 数据水的一批,\(O(n^3)\)暴力可过 实际上只要bitset优化一下floyd复杂度就是对的了(\(O(\frac{n^3}{32})\)) 还可以缩点之后bitset维 ...

    4. 前端开发面试题-JavaScript(转载)

      本文由 本文的原作者markyun 收集总结. 介绍js的基本数据类型. Undefined.Null.Boolean.Number.String. ECMAScript 2015 新增:Symbol ...

    5. Sqoop安装与应用过程

      1.  参考说明 参考文档: http://sqoop.apache.org/ http://sqoop.apache.org/docs/1.99.7/admin/Installation.html ...

    6. TensorFlow Saver 保存最佳模型 tf.train.Saver Save Best Model

        TensorFlow Saver 保存最佳模型 tf.train.Saver Save Best Model Checkmate is designed to be a simple drop-i ...

    7. Clumsy 弱网络环境模拟工具使用介绍

      Clumsy 弱网络环境模拟工具使用介绍 by:授客 QQ:1033553122 简介 利用封装 Winodws Filtering Platform 的WinDivert 库, clumsy 能实时 ...

    8. 【Redis】Redis学习(一) Redis初步入门

      一.Redis基础知识 1.1 Redis简介 Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理.它支持字符串.哈希表.列表.集合.有序集合,位图,h ...

    9. 【转】JS组件系列——Bootstrap组件福利篇:几款好用的组件推荐(二)

      前言:上篇 JS组件系列——Bootstrap组件福利篇:几款好用的组件推荐 分享了几个项目中比较常用的组件,引起了许多园友的关注.这篇还是继续,因为博主觉得还有几个非常简单.实用的组件,实在不愿自己 ...

    10. MySQL索引背后的数据结构及算法原理(employees实例)

      摘要 http://blog.codinglabs.org/articles/theory-of-mysql-index.html 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特 ...