mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
33 lines
1.4 KiB
HTML
33 lines
1.4 KiB
HTML
<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>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<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>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<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>
|