当前位置:网站首页>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;
}
};
边栏推荐
- Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
- Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
- Leetcode topic [array] -216- combined sum III
- Leetcode daily question solution: 717 1-bit and 2-bit characters - reverse order
- 如何在 R 中执行稳健回归
- Some knowledge of the beginning of 2022
- How do yaml files and zmail collide with the spark of the framework, and how can code and data be separated gracefully?
- (Video + graphics) introduction to machine learning series - Chapter 11 support vector machines
- Several key points for enterprises to pay attention to digital transformation
- Digital trend analysis of B2B e-commerce market mode and trading capacity in electronic components industry
猜你喜欢

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

Seven strategies for successfully integrating digital transformation
Online sequence flow chart making tool

SAP license: what is ERP supply chain

Recommend 14 commonly used test development tools

"2022" plans to change jobs and raise salary. It is necessary to ask interview questions and answers - browser

Software testing methods: a short guide to quality assurance (QA) models
![717.1-bit and 2-bit characters [sliding window]](/img/61/449566d2a8efbd403ae0361f839683.jpg)
717.1-bit and 2-bit characters [sliding window]
What if the database table structure changes? Smartbi products support one click synchronization
Ultimate Guide: comprehensive analysis of log analysis architecture of Enterprise Cloud native PAAS platform
随机推荐
浅谈云流送多人交互技术原理
布隆过滤器综述文章论文阅读:Optimizing Bloom Filter: Challenges, Solutions, and Comparisons
腾讯云荣获“可信云技术最佳实践-虚拟化”
25.sql statement differentiation
Online sequence flow chart making tool
13 ways to reduce the cost of cloud computing
The country has made a move! Launch network security review on HowNet
Business based precipitation component = & gt; manage-table
Top ten popular codeless testing tools
Bigdecimalavoiddoubleconstructorrule: do not directly use the double variable as a parameter to construct BigDecimal
Why are more and more people studying for doctors? Isn't it more and more difficult to graduate a doctor?
Industry Cloud video editing software
Common MySQL commands of installation free version
Business leaders compete for CIO roles
Data driven decision making: Decision intelligence and design thinking
Architecture decryption from distributed to microservice: several common microservice architecture schemes
Application service access configuration parameters
How does the video platform import the old database into the new database?
2022 network security C module of the secondary vocational group scans the script of the surviving target aircraft (municipal, provincial and national)
视频平台如何将旧数据库导入到新数据库?