你没考虑两个字符串一样长的问题,修改成一下就行 import java.util.*; public class Main { public static void main(String [] args) { Scanner sc = new Scanner(System.in); String s1 = sc.nextLine(); String s2 = sc.nextLine(); System.out.println(getPublicStr(s1, s2)); } public static int getPublicStr( String s1, String s2) { int count = 0; for (int i = 0; i < s1.length(); i++) { for (int j = s1.length(); j > i; j--) { if (s2.contains(s1.substring(i, j))) { count = Math.max(j - i, count); } } } return count; } }
点赞

相关推荐

03-23 15:00
已编辑
厦门大学 Java
xiaowl:你这个简历的问题是对于技术点、项目的描述,都是描述action的,对于面试官而言,仅能知道你干了什么,无法判断你为什么这么干,干的好不好。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务