java.lang.Object
g1801_1900.s1880_check_if_word_equals_summation_of_two_words.Solution

public class Solution extends Object
1880 - Check if Word Equals Summation of Two Words.<p>Easy</p> <p>The <strong>letter value</strong> of a letter is its position in the alphabet <strong>starting from 0</strong> (i.e. <code>'a' -> 0</code>, <code>'b' -> 1</code>, <code>'c' -> 2</code>, etc.).</p> <p>The <strong>numerical value</strong> of some string of lowercase English letters <code>s</code> is the <strong>concatenation</strong> of the <strong>letter values</strong> of each letter in <code>s</code>, which is then <strong>converted</strong> into an integer.</p> <ul> <li>For example, if <code>s = &quot;acb&quot;</code>, we concatenate each letter&rsquo;s letter value, resulting in <code>&quot;021&quot;</code>. After converting it, we get <code>21</code>.</li> </ul> <p>You are given three strings <code>firstWord</code>, <code>secondWord</code>, and <code>targetWord</code>, each consisting of lowercase English letters <code>'a'</code> through <code>'j'</code> <strong>inclusive</strong>.</p> <p>Return <code>true</code> <em>if the <strong>summation</strong> of the <strong>numerical values</strong> of</em> <code>firstWord</code> <em>and</em> <code>secondWord</code> <em>equals the <strong>numerical value</strong> of</em> <code>targetWord</code><em>, or</em> <code>false</code> <em>otherwise.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> firstWord = &ldquo;acb&rdquo;, secondWord = &ldquo;cba&rdquo;, targetWord = &ldquo;cdb&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>The numerical value of firstWord is &ldquo;acb&rdquo; -> &ldquo;021&rdquo; -> 21.</p> <p>The numerical value of secondWord is &ldquo;cba&rdquo; -> &ldquo;210&rdquo; -> 210.</p> <p>The numerical value of targetWord is &ldquo;cdb&rdquo; -> &ldquo;231&rdquo; -> 231.</p> <p>We return true because 21 + 210 == 231.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> firstWord = &ldquo;aaa&rdquo;, secondWord = &ldquo;a&rdquo;, targetWord = &ldquo;aab&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong></p> <p>The numerical value of firstWord is &ldquo;aaa&rdquo; -> &ldquo;000&rdquo; -> 0.</p> <p>The numerical value of secondWord is &ldquo;a&rdquo; -> &ldquo;0&rdquo; -> 0.</p> <p>The numerical value of targetWord is &ldquo;aab&rdquo; -> &ldquo;001&rdquo; -> 1.</p> <p>We return false because 0 + 0 != 1.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> firstWord = &ldquo;aaa&rdquo;, secondWord = &ldquo;a&rdquo;, targetWord = &ldquo;aaaa&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong></p> <p>The numerical value of firstWord is &ldquo;aaa&rdquo; -> &ldquo;000&rdquo; -> 0.</p> <p>The numerical value of secondWord is &ldquo;a&rdquo; -> &ldquo;0&rdquo; -> 0.</p> <p>The numerical value of targetWord is &ldquo;aaaa&rdquo; -> &ldquo;0000&rdquo; -> 0.</p> <p>We return true because 0 + 0 == 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= firstWord.length,</code> <code>secondWord.length,</code> <code>targetWord.length <= 8</code></li> <li><code>firstWord</code>, <code>secondWord</code>, and <code>targetWord</code> consist of lowercase English letters from <code>'a'</code> to <code>'j'</code> <strong>inclusive</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isSumEqual

      public boolean isSumEqual(String firstWord, String secondWord, String targetWord)