<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ascii &#8211; Huahua&#8217;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/ascii/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 31 Mar 2025 04:16:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>ascii &#8211; Huahua&#8217;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 3498 Reverse Degree of a String</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-3498-reverse-degree-of-a-string/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-3498-reverse-degree-of-a-string/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 31 Mar 2025 04:15:09 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=10247</guid>

					<description><![CDATA[送分题，简单仿真即可。 时间复杂度：O(n)空间复杂度：O(1) [crayon-67eadbf4411b6894152300/]]]></description>
										<content:encoded><![CDATA[
<p>送分题，简单仿真即可。</p>



<p>时间复杂度：O(n)<br>空间复杂度：O(1)</p>



<pre class="urvanov-syntax-highlighter-plain-tag">// https://zxi.mytechroad.com/blog/string/leetcode-3498-reverse-degree-of-a-string/
class Solution {
public:
  int reverseDegree(string s) {
    int ans = 0;
    for (int i = 0; i &lt; s.size(); ++i)
      ans += ('z' - s[i] + 1) * (i + 1);
    return ans;
  }
};</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/string/leetcode-3498-reverse-degree-of-a-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 712. Minimum ASCII Delete Sum for Two Strings</title>
		<link>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-712-minimum-ascii-delete-sum-for-two-strings/</link>
					<comments>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-712-minimum-ascii-delete-sum-for-two-strings/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sat, 21 Jul 2018 06:51:23 +0000</pubDate>
				<category><![CDATA[Dynamic Programming]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[dp]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=3236</guid>

					<description><![CDATA[Problem Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. Example 1: Input: s1 = "sea", s2&#8230;]]></description>
										<content:encoded><![CDATA[<p><iframe title="花花酱 LeetCode 712. Minimum ASCII Delete Sum for Two Strings - 刷题找工作 EP209" width="500" height="375" src="https://www.youtube.com/embed/RFBWavPKCJg?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<h1><strong>Problem</strong></h1>
<p>Given two strings <code>s1, s2</code>, find the lowest ASCII sum of deleted characters to make two strings equal.</p>
<p><b>Example 1:</b></p>
<pre class="crayon:false"><b>Input:</b> s1 = "sea", s2 = "eat"
<b>Output:</b> 231
<b>Explanation:</b> 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><b>Example 2:</b></p>
<pre class="crayon:false"><b>Input:</b> s1 = "delete", s2 = "leet"
<b>Output:</b> 403
<b>Explanation:</b> 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><b>Note:</b></p>
<ul>
<li><code>0 &lt; s1.length, s2.length &lt;= 1000</code>.</li>
<li>All elements of each string will have an ASCII value in <code>[97, 122]</code>.</li>
</ul>
<h1><strong>Solution: DP</strong></h1>
<p>Time complexity: O(l1 * l2)</p>
<p>Space complexity: O(l1 * l2)</p>
<p>C++</p><pre class="urvanov-syntax-highlighter-plain-tag">// Author: Huahua
// Running time: 8 ms
class Solution {
public:
  int minimumDeleteSum(string s1, string s2) {
    const int l1 = s1.length();
    const int l2 = s2.length();
    // dp[i][j] := min delete sum of (s1.substr(0, i), s2.substr(0, j))
    vector&lt;vector&lt;int&gt;&gt; dp(l1 + 1, vector&lt;int&gt;(l2 + 1));
    for (int i = 1; i &lt;= l1; ++i)
      dp[i][0] = dp[i - 1][0] + s1[i - 1];
    for (int j = 1; j &lt;= l2; ++j)
      dp[0][j] = dp[0][j - 1] + s2[j - 1];    
    for (int i = 1; i &lt;= l1; ++i)
      for (int j = 1; j &lt;= l2; ++j)
        if (s1[i - 1] == s2[j - 1])
          // keep s1[i - 1] and s2[j - 1]
          dp[i][j] = dp[i - 1][j - 1]; 
        else
          dp[i][j] = min(dp[i - 1][j] + s1[i - 1],  // delete s1[i - 1]
                         dp[i][j - 1] + s2[j - 1]); // delete s2[j - 1]
    return dp[l1][l2];
  }
};</pre><p></p>
<h1><strong>Solution2: Recursion + Memorization</strong></h1>
<p>Time complexity: O(l1 * l2)</p>
<p>Space complexity: O(l1 * l2)</p>
<p>C++</p><pre class="urvanov-syntax-highlighter-plain-tag">// Author: Huahua
// Running time: 20 ms
class Solution {
public:
  int minimumDeleteSum(string s1, string s2) {
    const int l1 = s1.length();
    const int l2 = s2.length();
    m_ = vector&lt;vector&lt;int&gt;&gt;(l1 + 1, vector&lt;int&gt;(l2 + 1, INT_MAX));
    return dp(s1, l1, s2, l2);
  }
private:
  int dp(const string&amp; s1, int i, const string&amp; s2, int j) {
    if (i == 0 &amp;&amp; j == 0) return 0;
    if (m_[i][j] != INT_MAX) return m_[i][j];
    if (i == 0) // s1 is empty.
      return m_[i][j] = dp(s1, i, s2, j - 1) + s2[j - 1];
    if (j == 0) // s2 is empty
      return m_[i][j] = dp(s1, i - 1, s2, j) + s1[i - 1];
    if (s1[i - 1] == s2[j - 1]) // skip s1[i-1] / s2[j-1]
      return m_[i][j] = dp(s1, i - 1, s2, j - 1);
    return m_[i][j] = min(dp(s1, i - 1, s2, j) + s1[i - 1],  // del s1[i-1]
                          dp(s1, i, s2, j - 1) + s2[j - 1]); // del s2[j-1]
  }  
  vector&lt;vector&lt;int&gt;&gt; m_;
};</pre><p></p>
<h1><strong>Related Problems</strong></h1>
<ul>
<li><a href="http://zxi.mytechroad.com/blog/dynamic-programming/leetcode-72-edit-distance/">花花酱 LeetCode 72. Edit Distance</a></li>
<li><a href="http://zxi.mytechroad.com/blog/dynamic-programming/leetcode-115-distinct-subsequences/">花花酱 LeetCode 115. Distinct Subsequences</a></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-712-minimum-ascii-delete-sum-for-two-strings/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
