当前位置:网站首页>Sliding window on the learning road
Sliding window on the learning road
2022-07-02 05:19:00 【[email protected]】
Sliding window is mainly used to reduce the number of iterations , When knowing the required range of data , You can quickly traverse by adding and subtracting .
class Solution {
public:
bool checkInclusion(string s1, string s2) {
int n=s1.size();
int t=s2.size();
vector<int>cnt1(26);
vector<int>cnt2(26);
if(t<n)
return false;
for(int i=0;i<n;i++)
{
cnt1[s1[i]-'a']++;
cnt2[s2[i]-'a']++;
}
if(cnt1==cnt2)// Two vector The container can directly judge whether it is equal
return true;
for(int i=n;i<t;i++)
{
cnt2[s2[i]-'a']++;
cnt2[s2[i-n]-'a']--;// Apply sliding window algorithm
if(cnt1==cnt2)
return true;
}
return false;
}
};版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202151846408088.html
边栏推荐
- 黑马笔记---Map集合体系
- How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
- The reason why sizeof (ARR) / sizeof (arr[0]) is used in the function to calculate the length of the array is incorrect
- Fabric.js 背景不受视口变换影响
- 摆正元素(带过渡动画)
- 从数组中找出和为目标的下标
- Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
- Case sharing | intelligent Western Airport
- Differential identities (help find mean, variance, and other moments)
- Detailed explanation of Pointer use
猜你喜欢

Gee: create a new feature and set corresponding attributes

Video multiple effects production, fade in effect and border background are added at the same time

黑马笔记---Map集合体系

Paddlepaddle project source code

Fabric.js 精简JSON

Fabric. JS activation input box

Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization

Black Horse Notes - - set Series Collection

Gee series: Unit 2 explore datasets

paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
随机推荐
Pyechats 1.19 generate a web version of Baidu map
Mapping settings in elk (8) es
Fabric. JS three methods of changing pictures (including changing pictures in the group and caching)
Principle and implementation of parallax effect
Gee series: unit 6 building various remote sensing indexes in Google Earth engine
Go implements leetcode rotation array
Collectors. Groupingby sort
How to make an RPM file
Differential identities (help find mean, variance, and other moments)
6.网络-基础
There are duplicate elements in leetcode. Go implementation
Fabric.js 3个api设置画布宽高
Thread pool batch processing data
Fabric. JS upload local image to canvas background
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
Two implementation methods of delay queue
Straighten elements (with transition animation)
Gee: create a new feature and set corresponding attributes
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
Gee dataset: chirps pentad high resolution global grid rainfall dataset