您的位置:首页 > 其它

【leetcode】第14题:Longest Common Prefix

2016-03-16 09:06 162 查看


代码如下:public static String findLongestPrefix(String[ ] str ){
String result = new String("");
if(str != null && str.length>0){
Arrays.sort(str);
}
String temp = new String();
temp = str[0] ;
for(int i = 0;i<temp.length(); i++){
if(str[str.length-1].length()>i&&str[str.length-1].charAt(i)==temp.charAt(i)){
result += temp.charAt(i);
}
else{
return result;
}
}
return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: