14. Longest Common Prefix
2016-04-22 10:46
225 查看
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; int len = strs.size(); if(len==0) return result; int len1 = strs[0].size(); for(int i = 0; i < len1; i++) { int count = 0; for(int j = 0; j < len; j++) { if(strs[0][i] == strs[j][i]) count ++; if(strs[0][i] != strs[j][i]) return result; } if(count== len) result += strs[0][i]; } return result; } };
相关文章推荐
- 解决方案 错误:HttpServlet was not found on the Java build path
- 为RecyclerView的不同item项实现不同的布局(添加分类Header)
- Unity3D 图形优化
- Unity3D 性能优化
- iOS 中UIView contentMode 属性总结
- 美国人、英国人、中国人一生都是如何度过
- proxool 连接池警告分析:appears to have started a thread named [HouseKeeper] but has failed to stop it
- 浏览器UA
- c++第三次实验
- kindeditor富文本注释掉上传网络图片
- 归并算法(java 语言实现)
- 王高利:CentOS6.5__VNC Server配置
- Jquery datePicker 日期联动效果
- Http协议与TCP协议简单理解
- C++第四次作业
- 揪出bug!解析调试神经网络的技巧
- MarkDown轻量使用
- Emoji表情符号录入MySQL数据库报错的解决方案
- Android——网格布局仿计算器
- Cisco VPP(7) 插件开发