Write a function to find the longest common prefix string amongst an array of strings.

 

 

 1 string longestCommonPrefix(vector<string>& strs) {
 2         int i=0,j=0;
 3         if(strs.size()==0)
 4         return "";
 5         int len=strs[0].length();
 6          int size=strs.size();
 7         string res;
 8         while(j<size)
 9         {
10             
11             
12             for(i=0;i<len;i++)
13             {
14                 if(strs[j][i]!=strs[0][i])
15                 break;
16             }
17             len=i;
18             j++;
19         }
20         for(j=0;j<i;j++)
21         res+=strs[0][j];
22         
23         return res;
24     }