Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Longest_Sub_String_without_Repeat_Characters_Dictionary
class Solution {
public:
int lengthOfLongestSubstring(string s) {
vector<int> dict(256,-1);
int maxLength = 0, start = -1;
for(int i =0; i<s.size(); i++)
{
if(dict[s[i]] > start)
start = dict[s[i]];
dict[s[i]] = i;
maxLength = max(maxLength, i - start);
}
return maxLength;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment