- Longest Substring Without Repeating Characters
class Solution {
public:
int lengthOfLongestSubstring(string s) {
vector<int> dictionary(256,-1);
int maxLen=0,init=-1;
for(int i=0;i<s.size();i++){
if(dictionary[s[i]]>init)
init=dictionary[s[i]];
dictionary[s[i]]=i;
maxLen=max(maxLen,i-init);
}
return maxLen;
}
};