Created
December 3, 2014 04:39
-
-
Save rohith2506/7a83d49405ec168bfdc3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: | |
# @return an integer | |
def lengthOfLongestSubstring(self, s): | |
prev_length = 0 | |
max_len = 0 | |
char_dict = {} | |
for i,c in enumerate(s): | |
if c in char_dict.keys() and (i - char_dict[c] <= prev_length): | |
prev_length = (i - char_dict[c]) | |
else: | |
prev_length = prev_length + 1 | |
if prev_length > max_len: | |
max_len = prev_length | |
char_dict[c] = i | |
return max_len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment