Create Solution.py

pull/7/head
buaazhangqi 5 years ago committed by GitHub
parent a88b3209a6
commit 4f4370b020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,19 @@
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
if len(s)<=1:
return len(s)
res = []
i = 0
j = 0
ans = 1
n = len(s)
while i<n and j<n:
if s[j] not in res:
res.append(s[j])
j+=1
ans = max(ans,j-i)
else:
res.remove(s[i])
i+=1
return ans
Loading…
Cancel
Save