*1062. Longest Repeating Substring

https://leetcode.com/problems/longest-repeating-substring/

solution

class Solution:
    def longestRepeatingSubstring(self, s: str) -> int:
        n = len(s)
        dp_table = [[0] * n for _ in range(n)]

        max_length = 0
        for i in range(n):
            for j in range(i + 1, n):
                if s[i] == s[j]:
                    dp_table[i][j] = dp_table[i - 1][j - 1] + 1 if i else 1
                    max_length = max(max_length, dp_table[i][j])

        return max_length

时间复杂度:O() 空间复杂度:O()

Last updated