首页 > 其他 > 详细

Leetcode 12

时间:2018-09-09 19:13:10      阅读:195      评论:0      收藏:0      [点我收藏+]
//日积月累,水滴石穿
class
Solution { public: string longestCommonPrefix(vector<string>& strs) { if (strs.empty()) return ""; //必须要加空的特判 string res = ""; for(int i=0;i < strs[0].size();i++){ for(int j=0;j < strs.size();j++){ if(i >= strs[j].size() || strs[j][i] != strs[0][i]) return res; } res.push_back(strs[0][i]); } return res; } }; int main() { string s[3] = {"abca","abc"}; //内容为string的vector vector<string> n; n.insert(n.begin(),s,s+2); Solution a; cout << a.longestCommonPrefix(n) << endl; return 0; }

_

Leetcode 12

原文:https://www.cnblogs.com/cunyusup/p/9614306.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!