LeetCode14. 最长公共前缀
class Solution {
public:
string longestCommonPrefix(vector<string>& s) {
string ans;
if (s.empty()) return ans;
ans = s[0];
for (int i = 1; i < s.size(); i++) {
for (int j = 0; j < ans.size(); j++) {
if (s[i][j] != ans[j]) {
ans.erase(ans.begin() + j, ans.end());
break;
}
}
}
return ans;
}
};