717. 1-bit and 2-bit Characters 1、2位字符
来源:互联网 发布:碑文 软件 编辑:程序博客网 时间:2024/05/21 18:37
We have two special characters. The first character can be represented by one bit0
. The second character can be represented by two bits (10
or11
).
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: TrueExplanation: 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: FalseExplanation: 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
.class Solution { public boolean isOneBitCharacter(int[] bits) { if(bits==null||bits[bits.length-1]!=0)return false; int n=bits.length; int i=0; while(i<n-1){ if(bits[i]==0)i++; else i=i+2; } return i==n-1; }}
题目解释:就是最后的一个必须是一位,只要遇到1就表示必然是两位挨着的,如11和10都符合2字符要求
阅读全文
0 0
- 717. 1-bit and 2-bit Characters 1、2位字符
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters。
- 717. 1-bit and 2-bit Characters
- 1-bit and 2-bit Characters
- leetCode-1-bit and 2-bit Characters
- 717 1-bit and 2-bit Characters
- 1-bit and 2-bit Characters(leetcode)
- LWC 56:717. 1-bit and 2-bit Characters
- 717. 1-bit and 2-bit Characters(第九周)
- LeetCode-717. 1-bit and 2-bit Characters
- Leetcode#717. 1-bit and 2-bit Characters
- 1-bit and 2-bit Characters:判断有1或2位编码构成的编码
- Springboot极简教程
- Linux下的文件系统
- 还纠结用哪个套餐呢?收好这几张图50元让你用9个G
- (转载)在后台运行Python脚本服务
- 【TensorFlow】官方MNIST数据集神经网络实例详解(六)
- 717. 1-bit and 2-bit Characters 1、2位字符
- 【CIO早班车】快来!不一样的知识管理体系只给不一般的企业用
- JavaSE练习-多线程、Socket(TCP协议)、IO流模拟实现服务端多线程接收客户端上传图片
- linux基本目录处理命令
- android linker 执行流程
- Vmware WorkStation Pro 12 安装记录
- 将SQL Server的任意记录转换为JSON格式(JQGRID) -- 支持SQL 2005
- tensorflow_add_layer
- 成为一名机器学习算法工程师,你需要这些必备技能