mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
23 lines
596 B
C++
23 lines
596 B
C++
class Solution{
|
|
public:
|
|
int LengthOfLongestSubString(string s){
|
|
int n = s.length();
|
|
int maxlen = 0;
|
|
unordered_set<char> charset;
|
|
int left = 0;
|
|
|
|
for(int right = 0;right<n;right++){
|
|
if(charset.count(s[right])==0){
|
|
charset.insert(s[right]);
|
|
maxlen = max(maxlen, right-left+1);
|
|
}while(charset.count(s[right])){
|
|
charset.erase(s[left]);
|
|
left++;
|
|
}
|
|
}
|
|
return maxlen;
|
|
|
|
|
|
}
|
|
}
|