Created
February 19, 2019 03:24
-
-
Save leafsummer/f114271e38fbed6b5a4d79bf09442440 to your computer and use it in GitHub Desktop.
[length of longest sub string]
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
def longest_substring(s): | |
res, start, n = 0, 0, 0, len(s) | |
maps = {} | |
for i in range(n): | |
start = max(start, maps.get(s[i], -1)+1) | |
res = max(res, i-start+1) | |
maps[s[i]] = i | |
return start, start+res-1, res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment