712. Minimum ASCII Delete Sum for Two Strings Medium

@problem@discussion
#String#Dynamic Programming



1/**
2 * [712] Minimum ASCII Delete Sum for Two Strings
3 *
4 * Given two strings s1 and s2, return the lowest ASCII sum of deleted characters to make two strings equal.
5 *  
6 * Example 1:
7 * 
8 * Input: s1 = "sea", s2 = "eat"
9 * Output: 231
10 * Explanation: Deleting "s" from "sea" adds the ASCII value of "s" (115) to the sum.
11 * Deleting "t" from "eat" adds 116 to the sum.
12 * At the end, both strings are equal, and 115 + 116 = 231 is the minimum sum possible to achieve this.
13 * 
14 * Example 2:
15 * 
16 * Input: s1 = "delete", s2 = "leet"
17 * Output: 403
18 * Explanation: Deleting "dee" from "delete" to turn the string into "let",
19 * adds 100[d] + 101[e] + 101[e] to the sum.
20 * Deleting "e" from "leet" adds 101[e] to the sum.
21 * At the end, both strings are equal to "let", and the answer is 100+101+101+101 = 403.
22 * If instead we turned both strings into "lee" or "eet", we would get answers of 433 or 417, which are higher.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= s1.length, s2.length <= 1000
28 * 	s1 and s2 consist of lowercase English letters.
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/
34// discuss: https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn minimum_delete_sum(s1: String, s2: String) -> i32 {
40        0
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_712() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.