你没考虑两个字符串一样长的问题,修改成一下就行 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; } }
点赞

相关推荐

不愿透露姓名的神秘牛友
07-07 14:00
不想多说了,什么逆天HR,还要教我礼貌😂
机械打工仔:这不纯傻卵吗,他还操心上别人老板了
投递BOSS直聘等公司8个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 11:22
点赞 评论 收藏
分享
MinJerous:虽然我一直说 计算机不怎么卡学历 但是至少得一本
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务