lintcode ---- 最长公共前缀
来源:互联网 发布:淘宝足球 编辑:程序博客网 时间:2024/06/03 16:27
思路:只要不相等就返回,否则res一直累加!
string longestCommonPrefix(vector<string> &strs) { // write your code here string res=""; int t = INT_MAX; if(strs.empty()) return res; else if(strs.size()==1) return strs[0]; //string tem = strs[0]; for(int i=0;i<strs.size();i++) { if(strs[i].length()<t) t=strs[i].length(); } for(int i=0;i<t;i++) { for(int j=0;j<strs.size();) { if(strs[j][i]==strs[0][i]) j++; else return res; } res+=strs[0][i]; } return res; }
0 0
- LintCode-最长公共前缀
- LintCode 最长公共前缀
- lintcode ---- 最长公共前缀
- LintCode : 最长公共前缀
- lintcode,最长公共前缀
- 最长公共前缀 -LintCode
- [Lintcode]最长公共前缀
- lintcode -- 最长公共前缀
- lintcode 最长公共前缀
- Lintcode(6)-最长公共前缀
- lintcode-最长公共前缀-78
- lintcode之最长公共前缀
- LintCode(M)最长公共前缀
- LintCode 78.最长公共前缀
- LintCode 78 最长公共前缀
- [Lintcode] #78 最长公共前缀
- [LintCode 78] 最长公共前缀(Python)
- lintcode python ——最长公共前缀(LCP)
- java中,map集合排序实例
- 修改Android系统中/system的读写权限
- socket
- php配置
- leetcode之全排列问题(Permutations)
- lintcode ---- 最长公共前缀
- Android Material Design 兼容库的使用详解
- SIP路由
- centOS下整合Tomcat和redis
- 怎么样把pdf转换成word文档
- Mina和Netty的选择
- c++ 单例模式
- 【bzoj2946】[Poi2000]公共串
- Calendar 的一些常见用法 如判断是否是同一天