题解 | 字符串距离计算

字符串距离计算

https://www.nowcoder.com/practice/82bd533cd9c34df29ba15bbf1591bedf

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 计算最少的距离
# @param S1 string字符串 第一个字符串
# @param S2 string字符串 第二个字符串
# @return int整型
#
class Solution:
    def GetMinDistance(self , s1 , s2 ):
        # write code here
        list_num=[]
        if len(s1)!=len(s2):
            return None
        if len(s1)>5e4 or len(s1)<1 :
            return None
        if not s1.islower():
            return None
        import string
        letters_low =list(string.ascii_lowercase)
        for x1 in letters_low:
            for x2 in letters_low:
                s1_copy=s1
                s1_copy=s1_copy.replace(x1,x2)
                num = 0
                for i in range(len(s1)):
                    if s1_copy[i]!=s2[i]:
                        num+=1
                list_num.append(num)

        return min(list_num)


全部评论

相关推荐

想run的马里奥在学...:这个学历帮你扫平百分之80的障碍,投就完了,这会找不到就等3月暑期一样能找到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务