longest_substring_without_repeating_characters

  • 2022-12-14
  • 浏览 (575)

longest_substring_without_repeating_characters.py 源码

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        res, m = 0, {}
        for c in s:
            if c in m:
                res = max(res, len(m))
                m.clear()
            m[c] = 1
        return max(res, len(m))


if __name__ == "__main__":
    sol = Solution()
    r = sol.lengthOfLongestSubstring("abcabcbb")
    print(r)

你可能感兴趣的文章

first_unique_char

implement_strstr

is_palindrome

0  赞