当前位置:网站首页>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;
}
};
边栏推荐
- Yolov5进阶之六目标追踪环境搭建
- Differential: definition of total differential, partial derivative, gradient
- Burpsuite -- brute force cracking of intruder
- Provincial election + noi part I dynamic planning DP
- 【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】
- Leetcode t31: next spread
- Provincial election + noi Part VI skills and ideas
- golang中的正则表达式使用注意事项与技巧
- 【Redis】一气呵成,带你了解Redis安装与连接
- 使用threejs简单Web3D效果
猜你喜欢

On several key issues of digital transformation

Field agricultural irrigation system

使用beef劫持用戶瀏覽器

Burpsuite -- brute force cracking of intruder

Set up file server Minio for quick use

Instead of houses, another kind of capital in China is rising
![[introduction] approximate value](/img/6b/597178d848dd21110f36601fc31092.png)
[introduction] approximate value

Access report realizes subtotal function
![[untitled]](/img/be/3523d0c14d555b293673af2b6fbcff.jpg)
[untitled]
![[redis] it takes you through redis installation and connection at one go](/img/ca/89cb18f0eeb835f021d6a2489681a1.png)
[redis] it takes you through redis installation and connection at one go
随机推荐
[untitled]
Embedded-c language-10-enumeration / (function) pointer (function) / multi-level pointer /malloc dynamic allocation / file operation
[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order
[deep analysis of C language] - data storage in memory
CPU設計實戰-第四章實踐任務一簡單CPU參考設計調試
C basic knowledge review (Part 4 of 4)
初学者如何正确理解google官方建议架构原则(疑问?)
[getting started] input n integers and output the smallest K of them
Leetcode t34: find the first and last positions of elements in a sorted array
Set up file server Minio for quick use
[staff] key number (key number identification position | key number marking list | a major key identification principle | F, C, G position marking ascending | F major key identification principle | B
Gateway-88
Uni hot update
[深度剖析C语言] —— 数据在内存中的存储
How to recruit Taobao anchor suitable for your own store
数字转excel的字符串坐标
使用threejs简单Web3D效果
Differential: definition of total differential, partial derivative, gradient
毕业论文中word的使用1-代码域标公式
The data analyst will be ruined without project experience. These 8 project resources will not be taken away