题目链接在这里:3. 无重复字符的最长子串 - 力扣(LeetCode)
这道题学习了几何函数set()的用法
1 class Solution(object): 2 def lengthOfLongestSubstring(self, s:str)->int: 3 n=len(s) 4 q=set() 5 lft=an=now=0 6 for i in range(n): 7 while s[i] in q: 8 now=i-lft 9 an=max(an,now) 10 q.remove(s[lft]) 11 lft+=1 12 q.add(s[i]) 13 an=max(an,i-lft+1) 14 return an 15 16 if __name__=="__main__": 17 s = "pwwkew" 18 ans=Solution.lengthOfLongestSubstring(self=0,s=s) 19 print(ans)
标签:子串,字符,lft,__,now,LeetCode From: https://www.cnblogs.com/keximeiruguo/p/17212660.html