全部 新建

user:thomas 由使用者建立的 Gists

title:mygist Gists 的標題

filename:myfile.txt Gists 的檔案名稱

extension:yml Gists 的副檔名

language:go Gists 的程式語言

topic:homelab gists with given topic

註冊

登錄

全部 新建 註冊 登錄

All gists matching topic interview

倒序排序 創建
順序排序 創建
倒序排序 更新
順序排序 更新

linkjobai / Edit Distance: A Dynamic Programming Walkthrough

0 喜歡
0 分支
1 檔案
最後活躍 5 days ago
Interview prep notes
interview

Edit Distance: A Dynamic Programming Walkthrough

Edit Distance (LeetCode 72) asks for the minimum number of insertions, deletions and substitutions that turn one word into another. It's the textbook two-string DP and a good template for many others.

Define the state

dp[i][j] = minimum edits to turn the first i characters of a into the first j characters of b.

  • If a[i-1] == b[j-1]: dp[i][j] = dp[i-1][j-1].
  • Otherwise: 1 + min(dp[i-1][j] (delete), dp[i][j-1] (insert), dp[i-1][j-1] (replace)).
上一頁 下一頁

由 Opengist 提供支持 ⋅ Load: 16ms⋅

繁體中文
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文