1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/检查某单词是否等于两单词之和 [check-if-word-equals-summation-of-two-words].html
2022-03-29 12:43:11 +08:00

55 lines
2.7 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>字母的 <strong>字母值</strong> 取决于字母在字母表中的位置,<strong>从 0 开始</strong> 计数。即,<code>'a' -&gt; 0</code><code>'b' -&gt; 1</code><code>'c' -&gt; 2</code>,以此类推。</p>
<p>对某个由小写字母组成的字符串 <code>s</code> 而言,其 <strong>数值</strong> 就等于将 <code>s</code> 中每个字母的 <strong>字母值</strong> 按顺序 <strong>连接</strong><strong>转换</strong> 成对应整数。</p>
<ul>
<li>例如,<code>s = "acb"</code> ,依次连接每个字母的字母值可以得到 <code>"021"</code> ,转换为整数得到 <code>21</code></li>
</ul>
<p>给你三个字符串 <code>firstWord</code><code>secondWord</code><code>targetWord</code> ,每个字符串都由从 <code>'a'</code><code>'j'</code> <strong>含 </strong><code>'a'</code><code>'j'</code><strong> </strong>)的小写英文字母组成。</p>
<p>如果 <code>firstWord</code><em> </em><em> </em><code>secondWord</code><strong>数值之和</strong> 等于<em> </em><code>targetWord</code><em> </em>的数值,返回 <code>true</code> ;否则,返回<em> </em><code>false</code><em> </em></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>firstWord = "acb", secondWord = "cba", targetWord = "cdb"
<strong>输出:</strong>true
<strong>解释:</strong>
firstWord 的数值为 "acb" -&gt; "021" -&gt; 21
secondWord 的数值为 "cba" -&gt; "210" -&gt; 210
targetWord 的数值为 "cdb" -&gt; "231" -&gt; 231
由于 21 + 210 == 231 ,返回 true
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>firstWord = "aaa", secondWord = "a", targetWord = "aab"
<strong>输出:</strong>false
<strong>解释:</strong>
firstWord 的数值为 "aaa" -&gt; "000" -&gt; 0
secondWord 的数值为 "a" -&gt; "0" -&gt; 0
targetWord 的数值为 "aab" -&gt; "001" -&gt; 1
由于 0 + 0 != 1 ,返回 false</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>firstWord = "aaa", secondWord = "a", targetWord = "aaaa"
<strong>输出:</strong>true
<strong>解释:</strong>
firstWord 的数值为 "aaa" -&gt; "000" -&gt; 0
secondWord 的数值为 "a" -&gt; "0" -&gt; 0
targetWord 的数值为 "aaaa" -&gt; "0000" -&gt; 0
由于 0 + 0 == 0 ,返回 true
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= firstWord.length, </code><code>secondWord.length, </code><code>targetWord.length &lt;= 8</code></li>
<li><code>firstWord</code><code>secondWord</code><code>targetWord</code> 仅由从 <code>'a'</code><code>'j'</code> <strong>含 </strong><code>'a'</code><code>'j'</code><strong> </strong>)的小写英文字母组成<strong></strong></li>
</ul>