Accepted Python solution


  • 0
    X
    class Solution:
        # @return an integer
        def lengthOfLongestSubstring(self, s):
            result = 0
            i = 0
            ptr = 0
            flag = True
            while i < len(s):
                if flag:
                    while ptr < len(s):
                        if s[ptr] not in s[i:ptr]:
                            ptr += 1
                        else:
                            result = max(result, ptr-i)
                            flag = False
                            break
                if ptr == len(s):
                    break
                if s[i] == s[ptr]:
                    flag = True
                i += 1
            return max(result, ptr-i)

Log in to reply
 

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