当前位置:网站首页>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
边栏推荐
- 7.1 simulation summary
- No logic is executed after the El form is validated successfully
- Ansible installation and use
- Fabric. JS 3 APIs to set canvas width and height
- Global and Chinese market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
- [quick view opencv] familiar with CV matrix operation with image splicing examples (3)
- Feign realizes file uploading and downloading
- Pyflink writes MySQL examples with JDBC
- Principle and implementation of parallax effect
- LeetCode 1175. Prime number arrangement (prime number judgment + Combinatorial Mathematics)
猜你喜欢
MySQL foundation --- query (learn MySQL foundation in 1 day)
Straighten elements (with transition animation)
Creation and destruction of function stack frames
Mathematical knowledge (Euler function)
Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line
LeetCode 1175. 质数排列(质数判断+组合数学)
Gee series: unit 9 generate sampling data in GEE [random sampling]
Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]
Ls1046nfs mount file system
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
随机推荐
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
4. Flask cooperates with a tag to link internal routes
Fabric. JS 3 APIs to set canvas width and height
Gee series: unit 6 building various remote sensing indexes in Google Earth engine
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
Gee series: Unit 4 data import and export in Google Earth engine
黑馬筆記---Set系列集合
Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
Record my pytorch installation process and errors
leetcode存在重复元素go实现
Pyechart1.19 national air quality exhibition
Global and Chinese market of commercial fish tanks 2022-2028: Research Report on technology, participants, trends, market size and share
Fabric.js IText 上标和下标
LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)
Case sharing | intelligent Western Airport
fastText文本分类
Collectors.groupingBy 排序
About PROFIBUS: communication backbone network of production plant