14. Longest Common Prefix.cpp
来源:互联网 发布:java 获取日期 编辑:程序博客网 时间:2024/06/03 18:15
/*
Write a function to find the longest common prefix string amongst an array of strings.
*/
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
string commo_str;
if(strs.size()==0) return commo_str;
for(int i = 0; i < strs[0].size() ;i++)
{
for(int j = 0 ; j < strs.size() ; j++)
{
if(strs[0][i] != strs[j][i])
return commo_str;
}
commo_str.push_back(strs[0][i]) ;
}
return commo_str;
}
};
Write a function to find the longest common prefix string amongst an array of strings.
*/
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
string commo_str;
if(strs.size()==0) return commo_str;
for(int i = 0; i < strs[0].size() ;i++)
{
for(int j = 0 ; j < strs.size() ; j++)
{
if(strs[0][i] != strs[j][i])
return commo_str;
}
commo_str.push_back(strs[0][i]) ;
}
return commo_str;
}
};
阅读全文
0 0
- 14. Longest Common Prefix.cpp
- Leetcode 14. Longest Common Prefix (Easy) (cpp)
- 14. Longest Common Prefix
- 14.Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- 14. Longest Common Prefix
- MVC框架简介
- 136.Single Number
- 特征分解
- 基于Spring Boot和Spring Cloud实现微服务架构学习(四)-Spring Cloud总结
- 史上最全的架构师图谱
- 14. Longest Common Prefix.cpp
- html手机页面开发模板
- jQuery的callback参数
- 如何提高测试工作效率
- org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
- Java学习笔记—JDBC(连接sqlserver)的用法
- ubuntu14.04手动更换内核方法
- AngularJs案例 购物车主页面
- 安卓集成mob并分享微信还有和朋友圈,以及分享完成的回调