lengthOfLongestSubstring accepted submission 1
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
# leetcode
|
# leetcode
|
||||||
|
|
||||||
|
I am starting out by doing the Blind 75, then Grind 75
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
class Solution:
|
||||||
|
def lengthOfLongestSubstring(self, s: str) -> int:
|
||||||
|
"""
|
||||||
|
>>> Solution().lengthOfLongestSubstring("abcabcbb")
|
||||||
|
3
|
||||||
|
>>> Solution().lengthOfLongestSubstring("bbbbb")
|
||||||
|
1
|
||||||
|
>>> Solution().lengthOfLongestSubstring("pwwkew")
|
||||||
|
3
|
||||||
|
"""
|
||||||
|
if s == "":
|
||||||
|
return 0
|
||||||
|
|
||||||
|
beginning = 0
|
||||||
|
end = 1
|
||||||
|
longest = 0
|
||||||
|
while end < len(s):
|
||||||
|
p = s[beginning:end]
|
||||||
|
if s[end] in s[beginning:end]:
|
||||||
|
if end - beginning > longest:
|
||||||
|
longest = end - beginning
|
||||||
|
beginning += 1
|
||||||
|
else:
|
||||||
|
end += 1
|
||||||
|
|
||||||
|
if end - beginning > longest:
|
||||||
|
longest = end - beginning
|
||||||
|
return longest
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import doctest
|
||||||
|
doctest.testmod()
|
||||||
Reference in New Issue
Block a user