Leetcode 72: Edit Distance

This problem is also known as the Levenshtein distance. It is possible to solve recursively but that is very inefficient. Here is how to do it with dynamic programming. My initial logic didn’t work with recurring characters. I’ve highlighted the fix in red.

Source for the above:
https://gist.github.com/adamkorg/38fa5934e9aeec0565d2f1dd50b73c3e
And here’s code for a variation with my current coding style tastes:

This entry was posted in programming and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *