Solution 1:

```
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if(strs.empty()) {
return "";
}
sort(strs.begin(), strs.end());
int count = 0;
while(true) {
if(count >= strs[0].size() || (strs[0][count] != strs[strs.size() - 1][count])) {
break;
}
count++;
}
return strs[0].substr(0, count);
}
};
```

Solution 2:

```
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if(strs.empty()) {
return "";
}
int count = 0;
while(true) {
for(int i = 0; i < strs.size(); i++) {
if(count >= strs[i].size() || (i > 0 && strs[i][count] != strs[i - 1][count])) {
return strs[0].substr(0, count);
}
}
count++;
}
return strs[0].substr(0, count);
}
};
```

Can anyone explain which algorithm is a little better?