当前位置:网站首页>717.1-bit and 2-bit characters [sliding window]
717.1-bit and 2-bit characters [sliding window]
2022-06-24 18:25:00 【@[toc] (directory)】
https://leetcode-cn.com/problems/1-bit-and-2-bit-characters/

This logic is so good 
simplify 
class Solution {
//0,10,11 It can transform
//1,01,00, These are known by reading questions , impossible 1,01 ending
//bits[i] = 1->i+=2
// 0->i++
public boolean isOneBitCharacter(int[] bits) {
int n = bits.length;
int i=0;
while(i<n){
if(i == n-1){
// If i It's the last one , Then go straight back
return true;
}
if(bits[i]==1){
i+=2;
}else{
i+=1;
}
}
return false;// If you traverse to the last second bit , Return to leave
}
}
Simplified version
class Solution {
public boolean isOneBitCharacter(int[] bits) {
int i=0;
int n = bits.length;
while(i<n-1){
if(bits[i]==1){
i+=2;
}
else{
i+=1;
}
}
return i == n-1;
}
}
Inspection point : The sliding window ,i++,i+=2 The logic of , And finally simplify the logic of judgment
Reference link :
https://www.bilibili.com/video/BV1Nr4y1r7A9
边栏推荐
- How do yaml files and zmail collide with the spark of the framework, and how can code and data be separated gracefully?
- NVM download, installation and use
- How to create simple shapes in illustrator 2022
- What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
- Restful design method
- Failure analysis | database failure MHA is not switched
- Nine practical guidelines for improving responsive design testing
- Selection (031) -cool_ How long can secret be accessed?
- Install MySQL using Yum for Linux
- What are the grades of financial products?
猜你喜欢

(Video + graphics) introduction to machine learning series - Chapter 11 support vector machines

Flutter dart regular regexp special characters $, () (IV)

Two micro service interviews where small companies suffer losses

Redis learning -- list of redis operations

13 ways to reduce the cost of cloud computing

Wechat applet to realize stacked rotation

NVM download, installation and use

Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs

How does the chief information security officer discuss network security with the enterprise board of directors

About pyqt5 to realize paging function (one window implements different interfaces)
随机推荐
You don't know about this inspection platform. It's a big loss!
Mysql database performance testing tool recommendation
Millions of dollars worth of NFT were stolen in the attack, and Google issued an emergency warning to 3.2 billion users worldwide | February 21 global network security hotspot
How can an enterprise successfully complete cloud migration?
Five skills of selecting embedded programming language
【你真的会用ES吗】ES基础介绍(一)
投资理财产品的钱能随时取出来吗?
C language | printf output function
Restful design method
R language Quantitative Ecology redundancy analysis RDA analysis plant diversity species data visualization
He "painted" what a smart city should look like with his oars
How to decompile APK files
Business leaders compete for CIO roles
Does the wave of layoffs in Chinese enterprises in 2021 need to be "judged" by morality?
Seven strategies for successfully integrating digital transformation
[can you really use es] Introduction to es Basics (I)
视频平台如何将旧数据库导入到新数据库?
Knowledge points of 2022 system integration project management engineer examination: ITSS information technology service
Easynvr fails to use onvif to detect the device. What is the reason why "no data" is displayed?
From file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql The GPG key to retrieve the key source "MySQL 5.7 community server" is installed, but not applicable to