Skip to content

Instantly share code, notes, and snippets.

@Youngestdev
Created July 3, 2020 13:03
Show Gist options
  • Select an option

  • Save Youngestdev/dea8f01ff54428ee3ceb15954420d571 to your computer and use it in GitHub Desktop.

Select an option

Save Youngestdev/dea8f01ff54428ee3ceb15954420d571 to your computer and use it in GitHub Desktop.
def deletion_distance(str1, str2):
@lru_cache(None)
def recursiveHelper(str3, str4):
if not str4 or not str3: return ''
idx = str3.find(str4[0])
store = (str4[0] + recursiveHelper(str3[idx+1:], str4[1:])) if idx != -1 else ''
return store if idx == 0 else max(store, recursiveHelper(str3, str4[1:]), key=len)
return len(str1) + len(str2) - 2*len(recursiveHelper(str1, str2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment