'''
Created on 2015年11月6日
@author: SphinxW
'''
# 長公共子串
#
# 給出兩個字符串,找到最長公共子串,并返回其長度。
#
#
# 您在真實的面試中是否遇到過這個題?
# 樣例
#
# 給出A=“ABCD”,B=“CBCE”,返回 2
# 注意
#
# 子串的字符應(yīng)該連續(xù)的出現(xiàn)在原字符串中,這與子序列有所不同。
class Solution:
# @param A, B: Two string.
# @return: the length of the longest common substring.
def longestCommonSubstring(self, A, B):
if len(B) == 0:
return 0
# write your code here
for length in range(1, len(B) + 1)[::-1]:
for index in range(len(B) - length + 1):
if A.find(B[index:index + length]) == -1:
pass
else:
return length
return 0