From : https://leetcode.com/problems/longest-common-prefix/
Write a function to find the longest common prefix string amongst an array of strings.
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if(strs.size() == 0) return "";
string s = "";
int len = strs.size(), flag;
for(int i=0; i<strs[0].length(); i++) {
char c = strs[0][i];
flag = 1;
for(int j=1; j<len; j++) {
char x = strs[j][i];
if(x != c) {flag=0;break; }
}
if(flag) {s += c;} else break;
}
return s;
}
};