Recca Chao 的 gitHub page

推廣網站開發,包含 Laravel 和 Kotlin 後端撰寫、自動化測試、讀書心得等。Taiwan Kotlin User Group 管理員。

View on GitHub

Hi, here’s your problem today. This problem was recently asked by AirBNB:

Given two strings, determine the edit distance between them. The edit distance is defined as the minimum number of edits (insertion, deletion, or substitution) needed to change one string to the other.

For example, “biting” and “sitting” have an edit distance of 2 (substitute b for s, and insert a t).

Here’s the signature:

def distance(s1, s2):
  # Fill this in.
print distance('biting', 'sitting')
# 2