java.lang.Object
g1301_1400.s1307_verbal_arithmetic_puzzle.Solution

public class Solution extends Object
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 = [&ldquo;SEND&rdquo;,&ldquo;MORE&rdquo;], result = &ldquo;MONEY&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> Map &lsquo;S&rsquo;-> 9, &lsquo;E&rsquo;->5, &lsquo;N&rsquo;->6, &lsquo;D&rsquo;->7, &lsquo;M&rsquo;->1, &lsquo;O&rsquo;->0, &lsquo;R&rsquo;->8, &lsquo;Y&rsquo;->&lsquo;2&rsquo; Such that: &ldquo;SEND&rdquo; + &ldquo;MORE&rdquo; = &ldquo;MONEY&rdquo; , 9567 + 1085 = 10652</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;SIX&rdquo;,&ldquo;SEVEN&rdquo;,&ldquo;SEVEN&rdquo;], result = &ldquo;TWENTY&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> Map &lsquo;S&rsquo;-> 6, &lsquo;I&rsquo;->5, &lsquo;X&rsquo;->0, &lsquo;E&rsquo;->8, &lsquo;V&rsquo;->7, &lsquo;N&rsquo;->2, &lsquo;T&rsquo;->1, &lsquo;W&rsquo;->&lsquo;3&rsquo;, &lsquo;Y&rsquo;->4 Such that: &ldquo;SIX&rdquo; + &ldquo;SEVEN&rdquo; + &ldquo;SEVEN&rdquo; = &ldquo;TWENTY&rdquo; , 650 + 68782 + 68782 = 138214</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> words = [&ldquo;LEET&rdquo;,&ldquo;CODE&rdquo;], result = &ldquo;POINT&rdquo;</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 Details

    • Solution

      public Solution()
  • Method Details

    • isSolvable

      public boolean isSolvable(String[] words, String result)