当前位置: 代码迷 >> 综合 >> JAVA算法:最长重复子串问题(JAVA解题)
  详细解决方案

JAVA算法:最长重复子串问题(JAVA解题)

热度:57   发布时间:2024-01-15 19:28:57.0

JAVA算法:最长重复子串问题(JAVA解题)

Given a string str, find the longest repeating non-overlapping substring in it. In other words find 2 identical substrings of maximum length which do not overlap. If there exists more than one such substring return any of them.

Examples:

Input : str = "geeksforgeeks"
Output : geeks

Input : str = "aab"
Output : a

Input : str = "aabaabaaba"
Output : aaba

Input : str = "aaaaaaaaaaa"
Output : aaaaa

Input : str = "banana"
Output : an 
         or na


算法设计

package com.bean.algorithm.basic;public class LongestRepeatingSubstring {// Returns the longest repeating non-overlapping// substring in strstatic String longestRepeatedSubstring(String str) {int n = str.length();int LCSRe[][] = new int[n + 1][n + 1];