Class Solution
java.lang.Object
g1301_1400.s1307_verbal_arithmetic_puzzle.Solution
1307 - Verbal Arithmetic Puzzle.<p>Hard</p>
<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><strong>Example 1:</strong></p>
<p><strong>Input:</strong> words = [“SEND”,“MORE”], result = “MONEY”</p>
<p><strong>Output:</strong> true</p>
<p><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</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> words = [“SIX”,“SEVEN”,“SEVEN”], result = “TWENTY”</p>
<p><strong>Output:</strong> true</p>
<p><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</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> words = [“LEET”,“CODE”], result = “POINT”</p>
<p><strong>Output:</strong> false</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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isSolvable
-