2022-03-27 20:46:41 +08:00
< p > Given two strings < code > s1< / code > and < code > s2< / code > , return < em > the lowest < strong > ASCII< / strong > sum of deleted characters to make two strings equal< / em > .< / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 20:46:41 +08:00
< pre >
< strong > Input:< / strong > s1 = " sea" , s2 = " eat"
< strong > Output:< / strong > 231
< strong > Explanation:< / strong > Deleting " s" from " sea" adds the ASCII value of " s" (115) to the sum.
Deleting " t" from " eat" adds 116 to the sum.
At the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 20:46:41 +08:00
< pre >
< strong > Input:< / strong > s1 = " delete" , s2 = " leet"
< strong > Output:< / strong > 403
< strong > Explanation:< / strong > Deleting " dee" from " delete" to turn the string into " let" ,
adds 100[d] + 101[e] + 101[e] to the sum.
Deleting " e" from " leet" adds 101[e] to the sum.
At the end, both strings are equal to " let" , and the answer is 100+101+101+101 = 403.
If instead we turned both strings into " lee" or " eet" , we would get answers of 433 or 417, which are higher.
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = s1.length, s2.length < = 1000< / code > < / li >
< li > < code > s1< / code > and < code > s2< / code > consist of lowercase English letters.< / li >
< / ul >