mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 14:57:08 +00:00
Time: 3545 ms (7.38%), Space: 15.6 MB (5.51%) - LeetHub
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
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
|
||||
Reference in New Issue
Block a user