Skip to content

Instantly share code, notes, and snippets.

@leafsummer
Created February 19, 2019 03:24
Show Gist options
  • Save leafsummer/f114271e38fbed6b5a4d79bf09442440 to your computer and use it in GitHub Desktop.
Save leafsummer/f114271e38fbed6b5a4d79bf09442440 to your computer and use it in GitHub Desktop.
[length of longest sub string]
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