class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
max = 0
myStr = ''
for char in s:
index = myStr.find(char)
if index == -1:
myStr+=char
else :
if len(myStr) > max:
max = len(myStr)
myStr = myStr[index + 1:] + char
if len(myStr) > max:
max = len(myStr)
return max
if __name__ == '__main__':
test = Solution()
print(test.lengthOfLongestSubstring('pwwkew '))
函数式leetcode-3
最新推荐文章于 2022-11-22 08:18:46 发布