当前位置:网站首页>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
边栏推荐
- Principle and implementation of parallax effect
- Gee series: unit 8 time series analysis in Google Earth engine [time series]
- Gee series: Unit 1 Introduction to Google Earth engine
- 【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
- Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
- Nodejs (02) - built in module
- 7.1模拟赛总结
- Fabric.js IText 上标和下标
- Mapping settings in elk (8) es
- Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
猜你喜欢

2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas

2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路

MySQL foundation --- query (learn MySQL foundation in 1 day)

Fabric. JS gradient

Pyechats 1.19 generate a web version of Baidu map

Record my pytorch installation process and errors

Fabric.js 激活输入框

操作符详解

Fabric.js IText 手动设置斜体

Dark horse notes -- Set Series Collection
随机推荐
视差特效的原理和实现方法
Fabric.js 圆形笔刷
ubuntu20.04安装mysql8
7. Eleven state sets of TCP
Fabric. JS round brush
leetcode两数相加go实现
Pyechats 1.19 generate a web version of Baidu map
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
Mathematical problems (number theory) trial division to judge prime numbers, decompose prime factors, and screen prime numbers
Gee: create a new feature and set corresponding attributes
Briefly introduce chown command
Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
Here comes the chicken soup! Keep this quick guide for data analysts
Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I
2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路
数据库批量插入数据
LeetCode 1175. 质数排列(质数判断+组合数学)
在{{}}中拼接字符
画波形图_数字IC