当前位置:网站首页>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;
}
};
边栏推荐
- Six configuration management tools that administrators must know
- Crmeb multi merchant PC packaging tutorial
- Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
- How MySQL works - Chapter 14
- Restful design method
- Industry Cloud video editing software
- Project Management Guide: tips, strategies and specific practices
- Specification for self test requirements of program developers
- [can you really use es] Introduction to es Basics (I)
- (Video + graphics) introduction to machine learning series - Chapter 11 support vector machines
猜你喜欢
An analysis of the comments on the TV series Douban by procedural apes

"2022" plans to change jobs and raise salary. It is necessary to ask interview questions and answers - browser
![717.1-bit and 2-bit characters [sliding window]](/img/61/449566d2a8efbd403ae0361f839683.jpg)
717.1-bit and 2-bit characters [sliding window]

Mariana Trench, Facebook's open source code analysis tool

How can programmers reduce bugs in development?

Regression testing strategy for comprehensive quality assurance system

Overall planning and construction method of digital transformation

Recommend 14 commonly used test development tools
Issue 39: MySQL time class partition write SQL considerations

Different JVM
随机推荐
Three indicators to help you measure the effectiveness of digital transformation
He "painted" what a smart city should look like with his oars
专有云TCE COS新一代存储引擎YottaStore介绍
Recommend a distributed JVM monitoring tool, which is very practical!
Knowledge points of 2022 system integration project management engineer examination: ITSS information technology service
[untitled]
Five skills of selecting embedded programming language
What are the grades of financial products?
Selection (032) - what is the output of the following code?
【leetcode】838. Push domino (Analog)
Considerations for it project demand analysis
Leetcode topic [array] -46- full arrangement
13 ways to reduce the cost of cloud computing
RestCloud ETL抽取动态库表数据实践
EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
Rapidssl getting started SSL certificate
如何在 R 中执行稳健回归
Project Management Guide: tips, strategies and specific practices
电子元器件行业B2B电商市场模式、交易能力数字化趋势分析
Restcloud ETL extracting dynamic library table data