1880. Check if Word Equals Summation of Two Words Easy
1/**
2 * [1880] Check if Word Equals Summation of Two Words
3 *
4 * The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.).
5 * The numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer.
6 *
7 * For example, if s = "acb", we concatenate each letter's letter value, resulting in "021". After converting it, we get 21.
8 *
9 * You are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive.
10 * Return true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.
11 *
12 * Example 1:
13 *
14 * Input: firstWord = "acb", secondWord = "cba", targetWord = "cdb"
15 * Output: true
16 * Explanation:
17 * The numerical value of firstWord is "acb" -> "021" -> 21.
18 * The numerical value of secondWord is "cba" -> "210" -> 210.
19 * The numerical value of targetWord is "cdb" -> "231" -> 231.
20 * We return true because 21 + 210 == 231.
21 *
22 * Example 2:
23 *
24 * Input: firstWord = "aaa", secondWord = "a", targetWord = "aab"
25 * Output: false
26 * Explanation:
27 * The numerical value of firstWord is "aaa" -> "000" -> 0.
28 * The numerical value of secondWord is "a" -> "0" -> 0.
29 * The numerical value of targetWord is "aab" -> "001" -> 1.
30 * We return false because 0 + 0 != 1.
31 *
32 * Example 3:
33 *
34 * Input: firstWord = "aaa", secondWord = "a", targetWord = "aaaa"
35 * Output: true
36 * Explanation:
37 * The numerical value of firstWord is "aaa" -> "000" -> 0.
38 * The numerical value of secondWord is "a" -> "0" -> 0.
39 * The numerical value of targetWord is "aaaa" -> "0000" -> 0.
40 * We return true because 0 + 0 == 0.
41 *
42 *
43 * Constraints:
44 *
45 * 1 <= firstWord.length, secondWord.length, targetWord.length <= 8
46 * firstWord, secondWord, and targetWord consist of lowercase English letters from 'a' to 'j' inclusive.
47 *
48 */
49pub struct Solution {}
50
51// problem: https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/
52// discuss: https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/?currentPage=1&orderBy=most_votes&query=
53
54// submission codes start here
55
56impl Solution {
57 pub fn is_sum_equal(first_word: String, second_word: String, target_word: String) -> bool {
58 false
59 }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_1880() {
70 }
71}
72
Back
© 2025 bowen.ge All Rights Reserved.