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.length ==0)
return "";
String pre = strs[0];
for (int i=0;i<strs.length;i++)
{
if(pre.length()==0||strs[i].length()==0)
return "";
int len = pre.length()<strs[i].length()?pre.length():strs[i].length();
int j;
for (j=0;j<len;j++)
{
if(pre.charAt(j)!=strs[i].charAt(j))
break;
}
pre = pre.substring(0,j);
}
return pre;
}
}