2017.9.26
就是慢慢比较呗
public class Solution {
/*
* @param strs: A list of strings
* @return: The longest common prefix
*/
public String longestCommonPrefix(String[] strs) {
// write your code here
String res = "";
int length = strs.length;
if(length <= 0){
return res;
}
if(length == 1){
return strs[0];
}
for(int i = 0; i < strs[0].length(); i++){
for(int j = 0; j < length - 1; j++){
if(strs[j].length() > i && strs[j+1].length() > i && strs[j].charAt(i) == strs[j+1].charAt(i)){
}
else{
return res;
}
}
res = res + strs[0].charAt(i);
}
return res;
}
}