题解 | #最长公共前缀#
最长公共前缀
http://www.nowcoder.com/practice/28eb3175488f4434a4a6207f6f484f47
import java.util.*;
public class Solution {
/**
*
* @param strs string字符串一维数组
* @return string字符串
*/
public String longestCommonPrefix (String[] strs) {
// write code here strs.startsWith() substring
if(strs.length==0)return "";
String s=strs[0];
for(int i=1;i<strs.length;i++){
while(!strs[i].startsWith(s)){//if(!strs[i].startsWith(s)){
s=s.substring(0,s.length()-1);//s=s.substring(0,strs.length()-1);
}
}
return s;
}
}