public static String longestCommonPrefix(String[] strs) {
if (strs.length == 0)
return "";
for (int i = 0; i < strs[0].length(); i++) {
for (int j = 1; j < strs.length; j++) {
if ((strs[j].length() <= i)
|| strs[0].charAt(i) != strs[j].charAt(i))
return strs[0].substring(0, i);
}
}
return strs[0];
}
14 Longest Common Prefix
最新推荐文章于 2021-07-09 19:44:36 发布