1062. Longest Repeating Substring

class Solution:
    def longestRepeatingSubstring(self, s: str) -> int:
        n = len(s)

        dp = [[0] * (n + 1) for _ in range(n + 1)]

        maxLen = 0

        for i in range(1, n + 1):
            for j in range(i + 1, n + 1):
                if s[i - 1] == s[j - 1]:
                    dp[i][j] = dp[i - 1][j - 1] + 1
                    maxLen = max(maxLen, dp[i][j])

        return maxLen
                

CleanShot 2024-09-02 at 14.40.21@2x.png