class Solution {
public String longestCommonPrefix(String[] strs) {
if (strs[0].length() == 0) return "";
if (strs.length == 1) return strs[0];
String str = strs[0];
for (int i = 0; i < strs.length; i++) {
if (!strs[i].startsWith(str)) {
str = str.substring(0, str.length() - 1);
i--;
}
}
return str;
}
}