class Solution {
public int longestRepeatingSubstring(String s) {
int n = s.length();
s = "#" + s;
int[][] dp = new int[n+1][n+1];
dp[0][0] = 0;
int max = 0; // 最少長度是 0
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i != j && s.charAt(i) == s.charAt(j)) {
dp[i][j] = dp[i-1][j-1] + 1;
max = Math.max(max, dp[i][j]);
}
}
}
return max;
}
}
/*
seen s as two string to compare
xxx[xxxxi]
x[xxxxj]
dp[i][j]: string s1 with ending i and string s2 with ending j, has the common substring len
if (S[i] == S[j]) so
if (S[i] == S[j]) dp[i][j] = dp[i-1][j-1] + 1;
*/