字符串操作:两个字符串的最长连续公共子串
2017-08-16 22:57
281 查看
public int findMatch(String number0, String number1){ if(number0 == null || number1 == null || !isNumeric(number0) || !isNumeric(number1)){ return 0; } if(number0.length() != number1.length()){ return -1; } int len = number0.length(); int[][] result = new int[len][len]; for(int i = 0; i < len; i++){ for(int j = 0; j < len; j++){ result[i][j] = 0; } } int maxLen = 0; int maxindex = 0; int i = 0; for(i=0;i<len;i++) { for(int j=0;j<len;j++) { if(number0.charAt(i) == number1.charAt(i)) { if(i != 0 && j != 0) { result[i][j]=result[i-1][j-1]+1; } if(i==0||j==0) { result[i][j]=1; } if(result[i][j]>maxLen) { maxLen = result[i][j]; maxindex=i+1-maxLen; } } } } return maxLen; }
相关文章推荐
- 两个字符串的最长连续公共子串
- 求两个字符串的最长的连续公共子串
- 求两个字符串的最长的连续公共子串
- 两个字符串的最长公共子串(子串为连续的)
- 两个字符串的最长连续公共子串
- 求两个字符串的最长的连续公共子串
- 求两个字符串的(连续的)最长公共子串
- 两个字符串的最长连续公共子串
- 求两个字符串的最长公共子串(包括连续和非连续)
- 多个字符串的公共最长连续子串(对两个字符串的扩展)
- 求两个字符串的最长的连续公共子串
- 求两个字符串的最长的连续公共子串(按位异或法)
- 求两个字符串的最长连续公共子串
- 求两个字符串的最长的连续公共子串和求两个字符串的公共子序列
- 华为机试---查找两个字符串a,b中的最长公共子串
- 后缀树和后缀数组 [3 两个字符串的最长公共子串]
- OJ------查找两个字符串a,b中的最长公共子串
- 求两字符串的最长公共连续子串
- 求解两个字符串的最长公共子串
- 实用算法实现-第 8 篇 后缀树和后缀数组 [3 两个字符串的最长公共子串]