Created
September 8, 2018 01:27
-
-
Save zhangxiaomu01/43518c4ea7a3e2904fe7f035a04fdfc4 to your computer and use it in GitHub Desktop.
Longest_Sub_String_without_Repeat_Characters_Dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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