leetcode717—1-bit and 2-bit Characters
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的更多相关文章
- [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 ...
- C#版[击败98.85%的提交] - Leetcode717. 1比特与2比特字符 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- LeetCode 717. 1比特与2比特字符(1-bit and 2-bit Characters)
717. 1比特与2比特字符 LeetCode717. 1-bit and 2-bit Characters 题目描述 有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- [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 ...
- [LeetCode] Sort Characters By Frequency 根据字符出现频率排序
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- 理解JVM之Java内存区域
Java虚拟机运行时数据区分为以下几个部分: 方法区.虚拟机栈.本地方法栈.堆.程序计数器.如下图所示: 一.程序计数器 程序计数器可看作当前线程所执行的字节码行号指示器,字节码解释器工作时就是通过改 ...
- Code Signal_练习题_evenDigitsOnly
Check if all digits of the given integer are even. Example For n = 248622, the output should beevenD ...
- python-原型模式
源码地址:https://github.com/weilanhanf/PythonDesignPatterns 说明 原型模式关注的是大量相同对象或相似对象的创建问题,意图在于通过复制一个已经存在的实 ...
- POJO、JAVABEAN、*O、EJB
POJO: 全称:Plain Old Java Object 解释:纯洁老式的java对象.从任何类继承.也没有实现任何接口,更没有被其它框架侵入的java对象 理解:通常我们常说的实体类 BEAN: ...
- PDO异常处理
PDO提供了三种处理错误的方式 PDO::ERRMODE_SILENT:静默模式(默认) PDO::ERRMODE_WARNING:警告模式 PDO::ERRMODE_EXCEPTION:异常模式 示 ...
- 设计模式(10)--Facade(外观模式)--结构型
作者QQ:1095737364 QQ群:123300273 欢迎加入! 1.模式定义: 外观模式提供了一个统一的接口,用来访问子系统中的一群接口.外观定义了一个高层接口,让子系统更容易使 ...
- javascript原型对象与原型链
在javascript中,当系统加载构造函授后 ,会自动在内存中增加一个对象,这个对象就是原型对象.构造函数和原型对象在内存中表现为相互独立,但两者之间还存在联系,构造函数的prototype是原型对 ...
- SLAM产品化的一些思考
这两年一直在做SLAM产品化的一些工作,有些感触,想和大家分享一下.很多想法只是个人浅见,不当之处还望大家指正. 我这两年分别做了AR眼镜和辅助驾驶方向的开发,说实话,挫折大于成果.SLAM产品化之难 ...
- Flutter:修改TextField的高度,以及无边框圆角
修改TextField的高度可以通过decoration: InputDecoration的contentPadding进行修改,代码如下 new TextField( decoration: Inp ...
- VS2010部署相关
找到一篇写得最负责的.贴住收藏了: http://blog.csdn.net/xhf55555/article/details/7702212. 之前在其它地方找的都缺胳膊少腿,真不知他们自己怎么实现 ...