当前位置:网站首页>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
边栏推荐
- Five advantages and disadvantages of Bi
- Error reported after NPM I
- TCE入围2020年工信部信创典型解决方案
- Mcu-08 interrupt system and external interrupt application
- 13 ways to reduce the cost of cloud computing
- How much does it cost to develop a small adoption program similar to QQ farm?
- Ultimate Guide: comprehensive analysis of log analysis architecture of Enterprise Cloud native PAAS platform
- How to select the best test cases for automation?
- Knowledge points of 2022 system integration project management engineer examination: ITSS information technology service
- Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs
猜你喜欢

ASP. Net hosting uploading file message 500 error in IIS
congratulate! The first dragon lizard community annual outstanding contribution award is announced. Check it now

Overall planning and construction method of digital transformation

Five skills of selecting embedded programming language
About swagger

Flutter dart regular regexp matches non printing characters \cl\cj\cm\ck

13 ways to reduce the cost of cloud computing

Etching process flow for PCB fabrication

It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements

About pyqt5 to realize paging function (one window implements different interfaces)
随机推荐
ASP. Net hosting uploading file message 500 error in IIS
PHP WMI get hostname
Do you know CMDB?
How about China Power Investment Xianrong futures? Is it safe to open futures accounts?
中电投先融期货这家公司怎么样?期货开户办理安全吗?
13 skills necessary for a competent QA Manager
Flutter dart regular regexp matches non printing characters \cl\cj\cm\ck
It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements
Easynvr fails to use onvif to detect the device. What is the reason why "no data" is displayed?
Tencent cloud won the "trusted cloud technology best practice - virtualization"
Nacos cluster starts throwing set of SQL_ SELECT_ LIMIT is not support
Error reported after NPM I
Noi Mathematics: solution of quadratic congruence equation
variable
Paper sharing | self supervised learning paper jointly released by Yann Lecun and read by engineers
Software testing methods: a short guide to quality assurance (QA) models
Skills of writing test cases efficiently
Three indicators to help you measure the effectiveness of digital transformation
Mengyou Technology: tiktok current limiting? Teach you to create popular copywriting + popular background music selection
Overall planning and construction method of digital transformation