class Solution {
public String longestCommonPrefix(String[] strs) {
if(strs == null || strs.length == 0)
return "";
char[] cs = null;
LinkedList<Character> sameChar = new LinkedList<>();
cs = strs[0].toCharArray();
for(char c : cs)
sameChar.add(c);
int csLen = sameChar.size();
for(String str : strs) {
//不需要判断了
//if(str == "")
// return "";
cs = str.toCharArray();
int i = 0;
int j = 0;
for(; j < cs.length; j++) {
if(i >= csLen)
break;
if(cs[j] != sameChar.get(i)) {
csLen = i;
break;
}
i++;
}
csLen = csLen > j ? j : csLen;
if(sameChar.isEmpty()) {
break;
}
}
int i = 0;
cs = new char[csLen];
while(i < csLen) {
cs[i] = sameChar.pollFirst();
i++;
}
return String.valueOf(cs);
}
}