Time: 4083 ms (7.65%), Space: 15.5 MB (5.68%) - LeetHub

This commit is contained in:
Deven
2022-05-18 16:56:54 -04:00
parent 9ba7f9dd13
commit 3a30e52296
@@ -0,0 +1,26 @@
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
letters = [x for x in s]
longestLength = 1
if len(letters) == 0: return 0
for i in range(len(letters)):
dictionary = {}
for j in range(i, len(letters)):
if dictionary.get(letters[j]) == None:
dictionary[letters[j]] = 0
else:
if j-i > longestLength:
longestLength = j-i
break
if j == len(letters) - 1:
if j-i+1 > longestLength:
longestLength = j-i+1
return longestLength
return longestLength