题解 | #最长公共前缀#
最长公共前缀
http://www.nowcoder.com/practice/28eb3175488f4434a4a6207f6f484f47
class Solution { public: string longestCommonPrefix(vector<string>& strs) { if (strs.empty()) return ""; string res = ""; for (int j = 0; j < strs[0].size(); ++j) { char c = strs[0][j]; for (int i = 1; i < strs.size(); ++i) { if (j >= strs[i].size() || strs[i][j] != c) { return res; } } res.push_back(c); } return res; } };
https://www.cnblogs.com/grandyang/p/4606926.html