class Solution {
public:
const std::vector<std::string> LongestCommonSubstring(const std::string& s1, const std::string& s2) {
if (s1.empty() || s2.empty()) {
return std::vector<std::string>();
} //dp
std::vector<std::vector<int>> dp(s1.size()+1,std::vector<int>(s2.size()+1,0));
int max_len=-1;
for(int i=1;i<s1.size()+1;i++) {
for(int j=1;j<s2.size()+1;j++) {
dp[i][j]=(s1[i-1]==s2[j-1])?dp[i-1][j-1]+1:0;
if(dp[i][j]>max_len) {
max_len=dp[i][j];
}
}
} //print result
std::vector<std::string> res;
for(int i=1;i<s1.size()+1;i++) {
for(int j=1;j<s2.size()+1;j++) {
if(dp[i][j]==max_len) {
res.push_back(s1.substr(i-max_len,max_len));
}
}
} return res;
}
};

最新文章

  1. linux下php-mysql拓展安装
  2. vs快捷键大全
  3. CFNetwork的错误代码参考
  4. db2数组、函数
  5. JS实现设为首页与加入收藏
  6. SQL Server 2012 各版本功能比较
  7. Bmob用户管理操作
  8. IntelliJ IDEA 15 显示工具栏及底部周边工具栏
  9. iOS多线程的初步研究(八)-- dispatch队列
  10. ZooKeeper编程指导
  11. 对于Java泛型的理解
  12. android studio友盟分享
  13. Java 线程池(ThreadPoolExecutor)原理分析与使用
  14. laravel5.5 任务调度 (转载)
  15. drf 多表
  16. Error creating bean with name &#39;student&#39;: Unsatisfied dependency expressed through field &#39;teacher&#39;; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating
  17. iOS ibeacon 使用详解
  18. linux 保留文件 其余删除
  19. mysql常用赋权命令
  20. Spark RDD Transformation 简单用例(二)

热门文章

  1. Mybatis总结一之Mybatis项目的创建
  2. 【转】深入 ProtoBuf - 简介
  3. 利用Docker手动构建WebLogic镜像的步骤
  4. hdu1072 逃离迷宫系列 bfs
  5. leetcode 签到 面试题40. 最小的k个数
  6. python中的抽象类
  7. Arcgis中制作热力图
  8. 基于vue-cli-和element-ui的开发admin(1)
  9. String是否相等、new的时候创建了几个对象等问题详解
  10. ADB 调试