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) {
return null;
}
if (strs.length == 0) {
return "";
}
String res = strs[0];
for (int i = 1; i < strs.length; i++) {
String curr = strs[i];
StringBuilder sb = new StringBuilder();
int j = 0;
while (j < res.length() && j < curr.length() && res.charAt(j) == curr.charAt(j)) {
sb.append(res.charAt(j));
j++;
}
res = sb.toString();
}
return res;
}
}