2020-02-25 Day3 Leetcode:3. Long

2020-02-25  本文已影响0人  YueTan
  1. Longest Substring Without Repeating Characters
    Given a string, find the length of the longest substring without repeating characters.
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        if len(s)==0:
            return 0
        max_out=1
        i,j=0,1
        while j<len(s):
            for index in range(i,j):
                if s[j]==s[index]:
                    i=index+1         
            
            max_out=max(max_out,j-i+1)
            j=j+1
        return max_out
      
            
        
上一篇 下一篇

猜你喜欢

热点阅读