Skip to content

Instantly share code, notes, and snippets.

@jchung05
Created October 21, 2018 17:25
Show Gist options
  • Save jchung05/1a5b01ee97d8e1471b85e9d469be0e23 to your computer and use it in GitHub Desktop.
Save jchung05/1a5b01ee97d8e1471b85e9d469be0e23 to your computer and use it in GitHub Desktop.
Solution to Q3 from Leetcode
def function(s:str)->int:
longest = 1
tmplongest = 0
chardict = {}
i = 0
if not s:
return 0
while i < len(s):
if s[i] in chardict.keys():
if tmplongest > longest:
longest = tmplongest
tmplongest = 0
chardict = {}
else:
chardict[s[i]] = True
tmplongest += 1
i += 1
return longest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment