class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if (strs.size() <= 0)
return "";
string result = "";
bool stop = false;
char comparedChar;
for (int i = 0; ; i++) {
comparedChar = strs[0][i];
for (int j = 0; j < strs.size(); j++) {
if (strs[j].size() <= i || strs[j][i] != comparedChar) {
stop = true;
break;
}
}
if (stop) break;
result += comparedChar;
}
return result;
}
};