Leetcode day1

This commit is contained in:
2026-01-25 12:41:33 +05:30
parent 686d174f19
commit 245116d181
14 changed files with 168 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int n =s.length();
vector<int>charIndex(128,-1);
int left = 0;
int maxlen =0;
for(int right =0;right<n;right++){
if(charIndex[s[right]]>=left){
left = charIndex[s[right]]+1;
}
charIndex[s[right]] = right;
maxlen = max(maxlen, right-left+1);
}
return maxlen;
}
};