Created
October 21, 2018 17:25
-
-
Save jchung05/1a5b01ee97d8e1471b85e9d469be0e23 to your computer and use it in GitHub Desktop.
Solution to Q3 from Leetcode
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
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