Write a function to find the longest common prefix string amongst an array of strings.
class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
string s;
int j = 0;
int n = strs.size();
if(strs.empty() == true)return s;
while(strs[0][j])
{
for(int i = 0; i < n-1; i++)
{
if((strs[i][j] == strs[i+1][j])&&(strs[i][j] != 0))continue;
else return s;
}
s += strs[0][j];
j++;
}
return s;
}
};