当前位置:网站首页>696. count binary substring
696. count binary substring
2022-06-24 18:33:00 【One star accompanies the moon】

This question belongs to one that can be , As soon as you do it, it will be useless
The length of the string is 5w, So we need to be linear or nlogn Time complexity of , But I used it at the very beginning n^2 Methods , direct TLE…
Normally speaking, it must take every point as the starting point , Look back , But then RE 了 (V-V)
Here is a good idea : We can count each paragraph 0(1) The length of , Then add up the smallest adjacent length . Take the example of the title 1 As an example, the length sequence of each segment is obtained :
[2,2,2,2]
that , The result is 2+2+2=6
Look at another set of data "00100":
[2,1,2]
that , The result is :1+1=2
What is the minimum length of two adjacent segments , Can be combined into how many xx01yy(yy10xx),0001111 For example , Its substring :000111 It's a situation , Substring :0011 It's also a situation ,01 It's also a situation , So there are three situations . Reduce the same amount each time 01, A new substring will be generated , So the shortest length is the number of substring occurrences
class Solution {
public:
int countBinarySubstrings(string s) {
int last=0,pre=0,len=s.size(),res=0,count,pos;
while(pre<len){
count=0;
pos=pre;
while(pre<len&&s[pre]==s[pos]){
count++;
pre++;
}
res+=min(count,last);
last=count;
}
return res;
}
};
边栏推荐
- RestCloud ETL抽取动态库表数据实践
- You don't know about this inspection platform. It's a big loss!
- 解决执行MapReduce程序控制台没有日志信息WARN Please initialize the log4j system properly
- Top ten popular codeless testing tools
- Implementation of pure three-layer container network based on BGP
- Ten excellent business process automation tools for small businesses
- Network security database penetration of secondary vocational group in 2022
- Is it safe to open an account online? What should I do?
- Paper sharing | self supervised learning paper jointly released by Yann Lecun and read by engineers
- Leetcode skimming questions - the 72nd biweekly match and 281 weekly match
猜你喜欢

Recommend a distributed JVM monitoring tool, which is very practical!

Considerations for it project demand analysis

Overall planning and construction method of digital transformation

He "painted" what a smart city should look like with his oars

(Video + graphics) introduction to machine learning series - Chapter 11 support vector machines
Ultimate Guide: comprehensive analysis of log analysis architecture of Enterprise Cloud native PAAS platform

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

Analysis on the issue of raising the right of MSSQL in 2021 secondary vocational group network security competition in Shandong Province

Number of occurrences of numbers in the array (medium difficulty)

Redis learning -- list of redis operations
随机推荐
How to start cloud native application development
Can the money invested in financial products be withdrawn at any time?
Issue 39: MySQL time class partition write SQL considerations
Industry Cloud video editing software
What are the reasons for the abnormal playback of the online channel of the channel accessed by easycvr national standard protocol?
Nine practical guidelines for improving responsive design testing
R language Quantitative Ecology redundancy analysis RDA analysis plant diversity species data visualization
视频平台如何将旧数据库导入到新数据库?
Two micro service interviews where small companies suffer losses
Skills of writing test cases efficiently
EasyGBS视频平台TCP主动模式拉流异常情况修复
面试算法 - 字符串问题总结
Optimizing bloom filter: challenges, solutions, and comparisons
持续助力企业数字化转型-TCE获得国内首批数字化可信服务平台认证
How to select the best test cases for automation?
Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
Mental models: the best way to make informed decisions - farnam
浅谈云流送多人交互技术原理
Specification for self test requirements of program developers
Rapidssl getting started SSL certificate