python simple two pointers solution


  • 1
    G
    class Solution(object):
        def lengthOfLongestSubstring(self, s):
            """
            :type s: str
            :rtype: int
            """
            if not s:
                return 0
            i,j,m,n=0,0,0,len(s)
            while j<n:
                if s[j] not in s[i:j]:
                    j+=1
                    m=max(m,j-i)
                else:
                    i+=1
            return m
            
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.