MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / editdistance

Method editdistance

Python/edit-distance.py:9–18  ·  view source on GitHub ↗
(i,j,s1=s1,s2=s2)

Source from the content-addressed store, hash-verified

7 def minDistance(self, s1: str, s2: str) -> int:
8 @lru_cache(None)
9 def editdistance(i,j,s1=s1,s2=s2):
10 if not i:
11 return j
12 if not j:
13 return i
14 if s1[i-1]==s2[j-1]:
15 return editdistance(i-1,j-1)
16 else:
17 return 1 + min(editdistance(i-1,j),editdistance(i,j-1),editdistance(i-1,j-1))
18 # Insert,Delete,replace
19 return editdistance(len(s1),len(s2),s1,s2)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected