3. Longest Substring Without Repeating Characters

class Solution:
    def lengthOfLongestSubstring(self, s):
          dict = {}
          ans = 0
          start = 0
          for i, c in enumerate(s):
              if c in dict:
                  start = max(start, dict[c]+1)
              dict[c] = i
              ans = max(ans, i-start+1)
          return ans

        
        

相关文章:

  • 2021-05-21
  • 2021-09-05
猜你喜欢
  • 2021-12-12
  • 2021-06-06
相关资源
相似解决方案