题解 | #公共子串计算#

公共子串计算

http://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b

抄袭大佬

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str1 = sc.nextLine();
            String str2 = sc.nextLine();
            if (str1.length() > str2.length()) {
                String temp = str1;
                str1 = str2;
                str2 = temp;
            }
            int maxSize = 0;
            for (int i = 0; i < str1.length(); i++) {
                for (int j = str1.length(); j > i; j--) {
                    if (str2.contains(str1.substring(i, j))) {
                        maxSize = Math.max(maxSize, j - i);
                    }
                }
            }
            System.out.println(maxSize);

        }
        sc.close();
    }

}
全部评论

相关推荐

牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务