Leetcode每日一题_14
public static String longestCommonPrefix(String[] strs) {
if(strs.length==0||strs==null)return "";
String res=strs[0];
for (int i = 1; i < strs.length; i++) {
while(strs[i].indexOf(res)!=0) {
res=res.substring(0,res.length()-1);
}
}
return res;
}
public static String longestCommonPrefix(String[] strs) {
if(strs.length==0||strs==null)return "";
String res=strs[0];
for (int i = 1; i < strs.length; i++) {
while(strs[i].indexOf(res)!=0) {
res=res.substring(0,res.length()-1);
}
}
return res;
}
全部评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享