Create Time: 3rd February 2024
Title: "[[SlidingWindow]]"
status: DONE
tags:
- SlidingWindow
- NOTE
- Algorithm
Author:
- AllenYGY
created: 2024-02-03
updated: 2024-06-22T16:18
SlidingWindow
int left=0;
for(int right=0;right<n;i++){
# 常常伴有哈系
while(condition){
left+=1;
}
# 更新ans
}
return ans;
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int ans=0,left=0,n=s.size();
unordered_map<char,int>m;
for(int right=0;right<n;right++){
m[s[right]]++;
while(m[s[right]]>1){
m[s[left]]--;
left++;
}ans=max(ans,right-left+1);
}
return ans;
}
};