712 Minimum ASCII Delete Sum for Two Strings
Given two strings s1, s2
, find the lowest ASCII sum of deleted characters to make two strings equal.
Example 1:
1 | Input: s1 = "sea", s2 = "eat" |
Example 2:
1 | Input: s1 = "delete", s2 = "leet" |
Note:
0 < s1.length, s2.length <= 1000
.
All elements of each string will have an ASCII value in [97, 122]
.
这个就是动态规划求解,所以要先建立dp[][]
二维数组,之后建立状态方程,需要循环遍历,依次从0开始查找dp[i][j]
的最小值。代码如下
1 | class Solution { |