python实现求两个字符串的最长公共子串
来源:互联网 发布:知乎重庆普瑞眼科医院 编辑:程序博客网 时间:2024/04/30 23:07
def initindexs(char,string): index = [] length = len(string) for i in range(length): if char == string[i]: index.append(i+1) #保存相同字符坐标+1的位置 return indexdef Substring(str1,str2): str1_len=len(str1) str2_len=len(str2) length=0 longest = 0 startposition = 0 start = 0 for i in range(str1_len): start = i index = initindexs(str1[i],str2) index_len = len(index) for j in range(index_len): end = i+1 while end <str1_len and index[j]<str2_len and str1[end] == str2[index[j]]:#保证下标不会超出列表范围 end += 1 index[j] += 1 length = end-start if length > longest: longest = length startposition = start return startposition,longeststr1 = "pmcdcdfe"str2 = 'aoccddcdfe'Substring(str1,str2)(start,longest) = Substring(str1,str2)print(start,longest)for i in range(longest): print(str1[start+i],end=' ')
0 0
- python实现求两个字符串的最长公共子串
- 求两个字符串的最长公共子串 python实现
- java实现求两个字符串的最长公共子字符串
- Python实现求两个字符串的最长公共子序列的算法
- 求两个字符串最长公共子串
- 求两个字符串的最长的连续公共子串
- 求两个字符串的最长的连续公共子串
- 求两个字符串的最长的连续公共子串
- 求两个字符串的最长的连续公共子串
- 求两个字符串的最长公共子串的长度
- 求两个字符串的最长公共子串的长度
- VB6求两个字符串最长公共子串的问题
- 求两个字符串的最长公共子串(LCS)
- 求两个字符串的最长公共子串
- 求两个字符串的最长公共子串
- 求两个字符串的最长公共子串(LCS)
- 求两个字符串最长公共子串的问题
- 求两个字符串的最长公共子串
- 自动装箱与拆箱
- 多线程编程面试题2
- iOS NSDateFormatter日期时间格式处理的用法
- linux多网卡的路由模式和桥接模式设置方法
- 多线程编程面试题3
- python实现求两个字符串的最长公共子串
- mybatis spring事务配置
- android 五种Toast显示方法
- C/C++中有关字长与平台无关的整数类型
- 全自动软化水设备:全自动软化水装置性能概述
- SimpleDateFormat的格式大全
- 金字塔
- 1
- Android 拍照并显示在ImageView中(进阶)