Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/43518c4ea7a3e2904fe7f035a04fdfc4 to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/43518c4ea7a3e2904fe7f035a04fdfc4 to your computer and use it in GitHub Desktop.
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