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)/口算难题 [verbal-arithmetic-puzzle].html

52 lines
2.3 KiB
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>给你一个方程,左边用&nbsp;<code>words</code>&nbsp;表示,右边用&nbsp;<code>result</code> 表示。</p>
<p>你需要根据以下规则检查方程是否可解:</p>
<ul>
<li>每个字符都会被解码成一位数字0 - 9</li>
<li>每对不同的字符必须映射到不同的数字。</li>
<li>每个 <code>words[i]</code><code>result</code>&nbsp;都会被解码成一个没有前导零的数字。</li>
<li>左侧数字之和(<code>words</code>)等于右侧数字(<code>result</code>)。&nbsp;</li>
</ul>
<p>如果方程可解,返回&nbsp;<code>True</code>,否则返回&nbsp;<code>False</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>words = [&quot;SEND&quot;,&quot;MORE&quot;], result = &quot;MONEY&quot;
<strong>输出:</strong>true
<strong>解释:</strong>映射 &#39;S&#39;-&gt; 9, &#39;E&#39;-&gt;5, &#39;N&#39;-&gt;6, &#39;D&#39;-&gt;7, &#39;M&#39;-&gt;1, &#39;O&#39;-&gt;0, &#39;R&#39;-&gt;8, &#39;Y&#39;-&gt;&#39;2&#39;
所以 &quot;SEND&quot; + &quot;MORE&quot; = &quot;MONEY&quot; , 9567 + 1085 = 10652</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>words = [&quot;SIX&quot;,&quot;SEVEN&quot;,&quot;SEVEN&quot;], result = &quot;TWENTY&quot;
<strong>输出:</strong>true
<strong>解释:</strong>映射 &#39;S&#39;-&gt; 6, &#39;I&#39;-&gt;5, &#39;X&#39;-&gt;0, &#39;E&#39;-&gt;8, &#39;V&#39;-&gt;7, &#39;N&#39;-&gt;2, &#39;T&#39;-&gt;1, &#39;W&#39;-&gt;&#39;3&#39;, &#39;Y&#39;-&gt;4
所以 &quot;SIX&quot; + &quot;SEVEN&quot; + &quot;SEVEN&quot; = &quot;TWENTY&quot; , 650 + 68782 + 68782 = 138214</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>words = [&quot;THIS&quot;,&quot;IS&quot;,&quot;TOO&quot;], result = &quot;FUNNY&quot;
<strong>输出:</strong>true
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>words = [&quot;LEET&quot;,&quot;CODE&quot;], result = &quot;POINT&quot;
<strong>输出:</strong>false
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= words.length &lt;= 5</code></li>
<li><code>1 &lt;= words[i].length,&nbsp;results.length&nbsp;&lt;= 7</code></li>
<li><code>words[i], result</code>&nbsp;只含有大写英文字母</li>
<li>表达式中使用的不同字符数最大为&nbsp;10</li>
</ul>