Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 72 Edit Distance - Operations

Three choices

You have three operations at each step:

1.1. Insert: Add a character to A. Moves from (i,j)(i, j) to (i,j1)(i, j-1) in DP (you matched B[j] by inserting).

2.2. Delete: Remove a character from A. Moves from (i,j)(i, j) to (i1,j)(i-1, j) (discarded A[i]).

3.3. Replace: Change a character in A. Moves from (i,j)(i, j) to (i1,j1)(i-1, j-1) (aligned A[i] with B[j]). Each operation costs 1. If characters match, no operation needed.