Approach hintTry it first, then revealHide
Define dp[i][j] as the cost to turn the first i characters into the first j. Insert, delete and replace correspond to the left, upper and diagonal neighbours; equal characters cost nothing. O(mn).
Define dp[i][j] as the cost to turn the first i characters into the first j. Insert, delete and replace correspond to the left, upper and diagonal neighbours; equal characters cost nothing. O(mn).