Write a function to find the longest common prefix string amongst an array of strings.
没啥难度,不多说了
public String longestCommonPrefix(String[] strs) {
if(strs.length < 1) return "";
String pre = strs[0];
int i =0;
while(i<strs.length){
while(strs[i].indexOf(pre) != 0){
pre = pre.substring(0,pre.length() -1);
}
i++;
}
return pre;
}
本站原创文章皆遵循“署名—非商业性使用—相同方式共享 4.0 协议 (CC BY-NC-SA 4.0)”。共享、演绎请保留以下标注: