当前位置:网站首页>Li Kou 1358 -- number of substrings containing all three characters (double pointer)
Li Kou 1358 -- number of substrings containing all three characters (double pointer)
2022-07-01 08:31:00 【lllzzzhhh2589】

Double finger needling
Find all that appears abc String , In the future, each additional person will have one more answer ;
Looking for all that appears abc String process with double finger needle method to avoid O(N^2) Overtime , Specific to the code is the right pointer plus , Left pointer minus
Complexity O(N)
class Solution {
public:
int numberOfSubstrings(string s) {
vector<int> cnt(3, 0);
int n = s.size();
int left = -1, right = 0;
int ans = 0;
while(right < n) {
cnt[s[right] - 'a']++;
if(cnt[0] && cnt[1] && cnt[2]) {
ans += n - right;
left++;
cnt[s[left] - 'a']--;
}
else {
right++;
}
}
return ans;
}
};
边栏推荐
- Provincial election + noi part I dynamic planning DP
- 2022 ordinary scaffolder (special type of construction work) examination question bank and the latest analysis of ordinary scaffolder (special type of construction work)
- Provincial election + noi Part VII computational geometry
- Leetcode t39: combined sum
- 《MATLAB 神经网络43个案例分析》:第30章 基于随机森林思想的组合分类器设计——乳腺癌诊断
- There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way
- Use threejs simple Web3D effect
- The difference between interceptors and filters
- 01 numpy introduction
- The use of word in graduation thesis
猜你喜欢

Gdip - hatchbrush pattern table

机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现

【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】

使用beef劫持用户浏览器

SPL Introduction (I)

Soft keyboard height error

Erreur de hauteur du clavier souple

Learn the knowledge you need to know about the communication protocol I2C bus

Serial port oscilloscope software ns-scope

Set up file server Minio for quick use
随机推荐
Learn reptiles for a month and earn 6000 a month? Tell you the truth about the reptile, netizen: I wish I had known it earlier
CPU design practice - Chapter 4 practical tasks - simple CPU reference design and debugging
Provincial election + noi Part VI skills and ideas
seaborn clustermap矩阵添加颜色块
【刷题】字符统计【0】
There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way
DID的使用指南,原理
【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】
How to recruit Taobao anchor suitable for your own store
Leetcode t34: find the first and last positions of elements in a sorted array
深度学习训练样本扩增同时修改标签名称
MATLAB小技巧(16)矩阵特征向量特征值求解一致性验证--层次分析
Deep learning systematic learning
【无标题】
Analysis of slice capacity expansion mechanism
SPL installation and basic use (II)
Codeworks round 803 (Div. 2) VP supplement
一套十万级TPS的IM综合消息系统的架构实践与思考
01 numpy introduction
使用threejs简单Web3D效果