当前位置:网站首页>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
边栏推荐
- EasyNVR使用Onvif探测设备失败,显示“无数据”是什么原因?
- 布隆过滤器综述文章论文阅读:Optimizing Bloom Filter: Challenges, Solutions, and Comparisons
- How do yaml files and zmail collide with the spark of the framework, and how can code and data be separated gracefully?
- System Verilog - randomize
- Yum to install warning:xxx: header V3 dsa/sha1 signature, key ID 5072e1f5: nokey
- Leetcode topic [array] -216- combined sum III
- What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
- TCE入围2020年工信部信创典型解决方案
- 【你真的会用ES吗】ES基础介绍(一)
- Number of occurrences of numbers in the array (medium difficulty)
猜你喜欢

Three layer switching experiment

How do yaml files and zmail collide with the spark of the framework, and how can code and data be separated gracefully?

How can an enterprise successfully complete cloud migration?

Software testing methods: a short guide to quality assurance (QA) models

Constantly changing the emergency dialing of harmonyos ETS during the new year

Several key points for enterprises to pay attention to digital transformation
[North Asia data recovery]_ mdb_ catalog. Mongodb database data recovery case in case of WT file corruption
An analysis of the comments on the TV series Douban by procedural apes
Issue 39: MySQL time class partition write SQL considerations

Business leaders compete for CIO roles
随机推荐
Overall planning and construction method of digital transformation
PHP WMI get hostname
Mcu-08 interrupt system and external interrupt application
Nine practical guidelines for improving responsive design testing
Selection (032) - what is the output of the following code?
Knowledge points of 2022 system integration project management engineer examination: ITSS information technology service
视频平台如何将旧数据库导入到新数据库?
EasyNVR使用Onvif探测设备失败,显示“无数据”是什么原因?
What are the grades of financial products?
Flutter dart regular regexp matches non printing characters \cl\cj\cm\ck
Three simple steps to quickly complete order data processing through workflow (ASW)
Leetcode skimming questions - the 72nd biweekly match and 281 weekly match
Three indicators to help you measure the effectiveness of digital transformation
What if the database table structure changes? Smartbi products support one click synchronization
Exception: Gradle task assembleDebug failed with exit code 1
Number of occurrences of numbers in the array (medium difficulty)
Ten excellent business process automation tools for small businesses
EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
Php7.4.28 installing the pcntl extension
Restcloud ETL extracting dynamic library table data