mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
47 lines
2.2 KiB
HTML
47 lines
2.2 KiB
HTML
<p>Given an equation, represented by <code>words</code> on the left side and the <code>result</code> on the right side.</p>
|
|
|
|
<p>You need to check if the equation is solvable under the following rules:</p>
|
|
|
|
<ul>
|
|
<li>Each character is decoded as one digit (0 - 9).</li>
|
|
<li>Every pair of different characters must map to different digits.</li>
|
|
<li>Each <code>words[i]</code> and <code>result</code> are decoded as one number <strong>without</strong> leading zeros.</li>
|
|
<li>Sum of numbers on the left side (<code>words</code>) will equal to the number on the right side (<code>result</code>).</li>
|
|
</ul>
|
|
|
|
<p>Return <code>true</code> <em>if the equation is solvable, otherwise return</em> <code>false</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> words = ["SEND","MORE"], result = "MONEY"
|
|
<strong>Output:</strong> true
|
|
<strong>Explanation:</strong> Map 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'
|
|
Such that: "SEND" + "MORE" = "MONEY" , 9567 + 1085 = 10652</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> words = ["SIX","SEVEN","SEVEN"], result = "TWENTY"
|
|
<strong>Output:</strong> true
|
|
<strong>Explanation:</strong> Map 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4
|
|
Such that: "SIX" + "SEVEN" + "SEVEN" = "TWENTY" , 650 + 68782 + 68782 = 138214</pre>
|
|
|
|
<p><strong>Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> words = ["LEET","CODE"], result = "POINT"
|
|
<strong>Output:</strong> false
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>2 <= words.length <= 5</code></li>
|
|
<li><code>1 <= words[i].length, result.length <= 7</code></li>
|
|
<li><code>words[i], result</code> contain only uppercase English letters.</li>
|
|
<li>The number of different characters used in the expression is at most <code>10</code>.</li>
|
|
</ul>
|