标签:
import java.util.Scanner; public class CodeCut { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); StringBuffer sb = new StringBuffer(str); String str1 = sb.reverse().toString(); String result = fun(str,str1); System.out.println(result.length()); } private static String fun(String str, String str1) { str = str.toLowerCase(); str1 = str1.toLowerCase(); for (int i = 0; i < str1.length(); i++) { for (int j = 0,k = str1.length()-i; k != str1.length() + 1; j++,k++) { String temp = str1.substring(j, k); if(str.contains(temp)) return temp; } } return null; } }注意:该题和之前求两个字符串的最大公共字符串的长度是一样的。
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/liaction/article/details/47786419