class Solution {//straightforward, and easy public: string longestCommonPrefix(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function if (strs.empty()) return ""; string result(""); for(int sii = 0; 1; ++sii){ for(int vjj = 0; vjj < strs.size(); ++vjj){ if (sii >= strs[vjj].size() || strs[0][sii] != strs[vjj][sii]){ return result; } } result.push_back(strs[0][sii]); } } };
No comments:
Post a Comment