Write a function to find the longest common prefix string amongst an array of strings.
一刷
public class Solution {
public String longestCommonPrefix(String[] strs) {
if(strs == null || strs.length == 0) return "";
for(int j=0; j<strs[0].length(); j++){
for(int i=0; i<strs.length; i++){
if(j >= strs[i].length() || strs[i].charAt(j) != strs[0].charAt(j))
return strs[0].substring(0, j);
}
}
return strs[0];
}
}