lintcode-最长公共子串-79
来源:互联网 发布:unity 删除整个数组 编辑:程序博客网 时间:2024/05/16 04:28
给出两个字符串,找到最长公共子串,并返回其长度。
样例
给出A=“ABCD”,B=“CBCE”,返回 2
注意
子串的字符应该连续的出现在原字符串中,这与子序列有所不同。
class Solution {public: int longestCommonSubstring(string &A, string &B) { if(A.empty()||B.empty()) return 0; int dp[A.length()+1][B.length()+1]; int maxp=0; memset(dp,0,sizeof(dp)); for(int i=1;i<A.length()+1;++i){ for(int j=1;j<B.length()+1;++j){ if(A[i-1]==B[j-1]) dp[i][j]=dp[i-1][j-1]+1; else dp[i][j]=0; maxp=max(maxp,dp[i][j]); } } return maxp; }};
0 0
- lintcode-最长公共子串-79
- LintCode 79 最长公共子串
- LintCode-最长公共子串
- LintCode 最长公共子串
- LintCode : 最长公共子串
- LintCode : 最长公共子串
- LintCode 最长公共子串
- 最长公共子串-LintCode
- lintcode -- 最长公共子串
- Lintcode(5)-最长公共子串
- lintcode 求最长公共子串
- lintcode 之 最长公共子串
- LintCode : 最长公共子序列
- LintCode 最长公共子序列
- 最长公共子序列-LintCode
- lintcode--最长公共子序列
- [Lintcode]Longest Common Substring最长公共子串
- Lintcode—(5)最长公共子串
- codeforces 2B B. The least round way(dp+数论)
- eclipse 快捷键
- Pointable类(Leap::Pointable)
- linux常用命令(33):df 命令
- Linux 安装Python3.4.3
- lintcode-最长公共子串-79
- java__集合的工具类
- rectint 函数
- linux grep命令
- 开启新的篇章
- 标准SQL的update语句三种用法
- POJ 1703Find them, Catch them(经典并查集)
- 将mongodb启动做成服务
- java中Map,List与Set的区别