# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @param t string字符串 # @return bool布尔型 # class Solution: def editdistance(self , s: str, t: str) -> bool: # 以下注释的写法会部分超时 # def inner(s1,s2): # dp=[[0 for j in range(len(s2)+1)] for i in range(len(s1)+1)] # dp[0]=[j for j in range(len(s2)+1)] # for i in range(len(s2)+1): # dp[i][0]=i # for i in range(1,len(s1)+1): # for j in range(1,len(s2)+1): # if s1[i-1]==s2[j-1]: # dp[i][j]=dp[i-1][j-1] # else: # dp[i][j]=min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])+1 # return dp[len(s1)][len(s2)] # if inner(s,t)==1: # return True # else: # return False L1,L2=len(s),len(t) if abs(L2-L1)>1: return False elif L1==L2: cou=0 for i in range(L1): if s[i]!=t[i]: cou+=1 if cou==1: return True else: return False else: s1,s2=(s,t) if L1<=L2 else (t,s) for i in s1: if i not in s2: return False return True