LeetCode 717. 1比特与2比特字符(1-bit and 2-bit Characters)
717. 1比特与2比特字符
LeetCode717. 1-bit and 2-bit Characters
题目描述
有两种特殊字符。第一种字符可以用一比特0来表示。第二种字符可以用两比特(10 或 11)来表示。
现给一个由若干比特组成的字符串。问最后一个字符是否必定为一个一比特字符。给定的字符串总是由0结束。
示例 1:
输入:
bits = [1, 0, 0]
输出: True
解释:
唯一的编码方式是一个两比特字符和一个一比特字符。所以最后一个字符是一比特字符。
示例 2:
输入:
bits = [1, 1, 1, 0]
输出: False
解释:
唯一的编码方式是两比特字符和两比特字符。所以最后一个字符不是一比特字符。
注意:
- 1 <= len(bits) <= 1000.
- bits[i] 总是0 或 1.
Java 实现
class Solution {
public boolean isOneBitCharacter(int[] bits) {
int count = 0;
for (int i = bits.length - 2; i >= 0 && bits[i] != 0; i--) {
count++;
}
if (count % 2 == 1) {
return false;
}
return true;
}
}
参考资料
- https://leetcode-cn.com/problems/1-bit-and-2-bit-characters/
- https://leetcode.com/problems/1-bit-and-2-bit-characters/
LeetCode 717. 1比特与2比特字符(1-bit and 2-bit Characters)的更多相关文章
- Java实现 LeetCode 717 1比特与2比特字符(暴力)
717. 1比特与2比特字符 有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 11)来表示. 现给一个由若干比特组成的字符串.问最后一个字符是否必定为一个一比特字符. ...
- C#版[击败98.85%的提交] - Leetcode717. 1比特与2比特字符 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- LeetCode(3):无重复字符的最大子串
本内容是LeetCode第三道题目:无重复字符的最大子串 # -*- coding: utf-8 -*- """ Created on Sun Mar 10 20:14: ...
- LeetCode 第 3 题:无重复字符的最长子串(滑动窗口)
LeetCode 第 3 题:无重复字符的最长子串 (滑动窗口) 方法:滑动窗口 滑动窗口模板问题:右指针先走,满足了一定条件以后,左指针向前走,直到不满足条件. 特点:左右指针的方向是一致的,并且是 ...
- C#LeetCode刷题之#717-1比特与2比特字符( 1-bit and 2-bit Characters)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3740 访问. 有两种特殊字符.第一种字符可以用一比特0来表示.第 ...
- [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 ...
- Leetcode717.1-bit and 2-bit Characters1比特与2比特字符
有两种特殊字符.第一种字符可以用一比特0来表示.第二种字符可以用两比特(10 或 11)来表示. 现给一个由若干比特组成的字符串.问最后一个字符是否必定为一个一比特字符.给定的字符串总是由0结束. 示 ...
- Leetcode 190. Reverse Bits(反转比特数)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- [LeetCode] Shortest Distance to a Character 到字符的最短距离
Given a string S and a character C, return an array of integers representing the shortest distance f ...
随机推荐
- Python轮子
代码复用 会用到的轮子贴在这篇文章中,备用.
- 自定义Robotframework,Appium的一个关键字(用于点击目标图片,用于Appium无法识别的一些图片元素)
Appium无法识别的一些图片元素,必须先通过图片找坐标,进而通过点击坐标解决问题. 1.先在terminer运行安装命令: pip install robotframework-appiumlib ...
- 点击Button按钮实现页面跳转
1.首先我们新建一个带有button按钮的页面 <button type="submit" class="form-contrpl">注册</ ...
- 类似hover的css伪类注解
a:link { font-size: 14pt; text-decoration: underline; color: blue; } /*设置a对象在未被访问前的样式表属性 .*/ a:hover ...
- Linux源码编译nginx
1.安装nginx 安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 首先要安装 ...
- Codeforces J. Soldier and Number Game(素数筛)
题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...
- scapy 中sniff指定的数据包并打印指定信息
在理解这篇文章前可以先看看这两篇文章: https://www.cnblogs.com/liyuanhong/p/10925582.html https://www.cnblogs.com/liyua ...
- 前端html页面,手机查看
在写前端页面中,经常会在浏览器运行HTML页面,从本地文件夹中直接打开的一般都是file协议,当代码中存在http或https的链接时,HTML页面就无法正常打开,为了解决这种情况,需要在在本地开启一 ...
- Eye sketch - ES
An interesting painting program, the interface is a blank drawing board, touch the bottom of the r ...
- ABP 网站发布
报错1:HTTP Error 503. The service is unavailable. 解决:IIS->应用程序池->高级设置->进程模型->标识.将内置账户更改为Ne ...