classSolution {publicintlongestRepeatingSubstring(String s) {int n =s.length(); s ="#"+ s;int[][] dp =newint[n+1][n+1]; dp[0][0] =0;int max =0; // 最少長度是 0for (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 comparexxx[xxxxi]x[xxxxj]dp[i][j]: string s1 with ending i and string s2 with ending j, has the common substring lenif (S[i] == S[j]) so if (S[i] == S[j]) dp[i][j] = dp[i-1][j-1] + 1;*/