题解 | #公共子串计算#
公共子串计算
https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s1 = scanner.nextLine();
String s2 = scanner.nextLine();
int length = 0;
for (int i = 0; i < s1.length(); i++) {
int tmp = 0;
for (int j = i + 1; j <= s1.length(); j++) {
String s = s1.substring(i, j);
if (s2.contains(s) && j != s1.length()) {
tmp++;
continue;
} else if (s2.contains(s) && j == s1.length()) {
tmp++;
if (tmp > length) {
length = tmp;
}
} else {
if (tmp > length) {
length = tmp;
}
}
}
}
System.out.println(length);
}
}


顺丰集团工作强度 276人发布