1307. Verbal Arithmetic Puzzle Hard
1/**
2 * [1307] Verbal Arithmetic Puzzle
3 *
4 * Given an equation, represented by words on the left side and the result on the right side.
5 * You need to check if the equation is solvable under the following rules:
6 *
7 * Each character is decoded as one digit (0 - 9).
8 * No two characters can map to the same digit.
9 * Each words[i] and result are decoded as one number without leading zeros.
10 * Sum of numbers on the left side (words) will equal to the number on the right side (result).
11 *
12 * Return true if the equation is solvable, otherwise return false.
13 *
14 * Example 1:
15 *
16 * Input: words = ["SEND","MORE"], result = "MONEY"
17 * Output: true
18 * Explanation: Map 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'
19 * Such that: "SEND" + "MORE" = "MONEY" , 9567 + 1085 = 10652
20 * Example 2:
21 *
22 * Input: words = ["SIX","SEVEN","SEVEN"], result = "TWENTY"
23 * Output: true
24 * Explanation: Map 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4
25 * Such that: "SIX" + "SEVEN" + "SEVEN" = "TWENTY" , 650 + 68782 + 68782 = 138214
26 * Example 3:
27 *
28 * Input: words = ["LEET","CODE"], result = "POINT"
29 * Output: false
30 * Explanation: There is no possible mapping to satisfy the equation, so we return false.
31 * Note that two different characters cannot map to the same digit.
32 *
33 *
34 * Constraints:
35 *
36 * 2 <= words.length <= 5
37 * 1 <= words[i].length, result.length <= 7
38 * words[i], result contain only uppercase English letters.
39 * The number of different characters used in the expression is at most 10.
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/verbal-arithmetic-puzzle/
45// discuss: https://leetcode.com/problems/verbal-arithmetic-puzzle/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn is_solvable(words: Vec<String>, result: String) -> bool {
51 false
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_1307() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.