Class Solution
- 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.Easy
The letter value of a letter is its position in the alphabet starting from 0 (i.e.
'a' -> 0,'b' -> 1,'c' -> 2, etc.).The numerical value of some string of lowercase English letters
sis the concatenation of the letter values of each letter ins, which is then converted into an integer.- For example, if
s = "acb", we concatenate each letter’s letter value, resulting in"021". After converting it, we get21.
You are given three strings
firstWord,secondWord, andtargetWord, each consisting of lowercase English letters'a'through'j'inclusive.Return
trueif the summation of the numerical values offirstWordandsecondWordequals the numerical value oftargetWord, orfalseotherwise.Example 1:
Input: firstWord = “acb”, secondWord = “cba”, targetWord = “cdb”
Output: true
Explanation:
The numerical value of firstWord is “acb” -> “021” -> 21.
The numerical value of secondWord is “cba” -> “210” -> 210.
The numerical value of targetWord is “cdb” -> “231” -> 231.
We return true because 21 + 210 == 231.
Example 2:
Input: firstWord = “aaa”, secondWord = “a”, targetWord = “aab”
Output: false
Explanation:
The numerical value of firstWord is “aaa” -> “000” -> 0.
The numerical value of secondWord is “a” -> “0” -> 0.
The numerical value of targetWord is “aab” -> “001” -> 1.
We return false because 0 + 0 != 1.
Example 3:
Input: firstWord = “aaa”, secondWord = “a”, targetWord = “aaaa”
Output: true
Explanation:
The numerical value of firstWord is “aaa” -> “000” -> 0.
The numerical value of secondWord is “a” -> “0” -> 0.
The numerical value of targetWord is “aaaa” -> “0000” -> 0.
We return true because 0 + 0 == 0.
Constraints:
1 <= firstWord.length,secondWord.length,targetWord.length <= 8firstWord,secondWord, andtargetWordconsist of lowercase English letters from'a'to'j'inclusive.
- For example, if
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisSumEqual(String firstWord, String secondWord, String targetWord)
-