leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0014.cpp (427B)
0 class Solution {
1 public:
2 string longestCommonPrefix(vector<string> &strs) {
3 int mlen = 200;
4 for (string &s : strs)
5 mlen = min(mlen, (int)s.size());
7 string res = "";
8 for (int i = 0; i < mlen; i++) {
9 for (int j = 1; j < strs.size(); j++)
10 if (strs[j][i] != strs[0][i]) return res;
11 res += strs[0][i];
12 }
13 return res;
14 }
15 };