less than 1 minute read

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        q = []
        max = 0
        for i in range(len(s)):
            for j in list(s)[i:]:
                if j not in q:
                    q.append(j)
                else:
                    if max < len(q):
                        max = len(q)
                    q = []
                    break
            else:
                if max < len(q):
                    max = len(q)
                q = []
        return max


if __name__ == "__main__":
    print(Solution().lengthOfLongestSubstring("pwwkew"))

Categories:

Updated:

Comments