Created
July 3, 2020 13:03
-
-
Save Youngestdev/dea8f01ff54428ee3ceb15954420d571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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