A EASY problem, just for accomplish today's task.
Already late again
DESCRIPTION:
Write a function to find the longest common prefix string amongst an array of strings.
ANALYSIS:
So easy!
Just was a little worried about TimeLimit. And some problems with index dealing.
SOLUTION:
public static String longestCommonPrefix(String[] strs) {
if(strs.length==0)
return "";
int l = strs.length;
int count = 0;
while (count < strs[0].length()) {
int i;
for (i = 0; i < l; i++) {
if (strs[i].length() == count
|| strs[i].charAt(count) != strs[0].charAt(count)) {
return strs[0].substring(0, count);
}
}
if (i == l)
count++;
}
return strs[0].substring(0, count);
}