求两个字符串的最长公共子串——Java实现

2021-07-12 16:07

阅读:729

标签:def   公共子串   soscw   oid   sys   img   current   bcd   bst   

要求:求两个字符串的最长公共子串,如“abcdefg”和“adefgwgeweg”的最长公共子串为“defg”(子串必须是连续的)

public class Main03{
	// 求解两个字符号的最长公共子串
	public static String maxSubstring(String strOne, String strTwo){
		// 参数检查
		if(strOne==null || strTwo == null){
			return null;
		}
		if(strOne.equals("") || strTwo.equals("")){
			return null;
		}
		// 二者中较长的字符串
		String max = "";
		// 二者中较短的字符串
		String min = "";
		if(strOne.length() 

  技术分享图片

总觉得这题,输出结果和题意不相符合,结果2,是不是把B序列翻转,求出两者最长公共子串

求两个字符串的最长公共子串——Java实现

标签:def   公共子串   soscw   oid   sys   img   current   bcd   bst   

原文地址:https://www.cnblogs.com/hgc-bky/p/9545355.html


评论


亲,登录后才可以留言!