标签:
Write a function to find the longest common prefix string amongst an array of strings.
class Solution { public: string longestCommonPrefix(vector<string>& strs) { string result = ""; if(strs.empty()) return result; for(int i = 0; i < strs[0].size(); i++) { for(int j = 1; j < strs.size(); j++) { if(strs[j - 1][i] != strs[j][i]) return result; } result += strs[0][i]; } return result; } };
标签:
原文地址:http://www.cnblogs.com/dylqt/p/4922357.html