• [Swift]LeetCode1307. 口算难题 | Verbal Arithmetic Puzzle


    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(let_us_code)
    ➤博主域名:https://www.zengqiang.org
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/12151686.html
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    Given an equation, represented by words on left side and the result on right side.

    You need to check if the equation is solvable under the following rules:

    Each character is decoded as one digit (0 - 9).
    Every pair of different characters they must map to different digits.
    Each words[i] and result are decoded as one number without leading zeros.
    Sum of numbers on left side (words) will equal to the number on right side (result). 
    Return True if the equation is solvable otherwise return False.

    Example 1:

    Input: words = ["SEND","MORE"], result = "MONEY"
    Output: true
    Explanation: Map 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'
    Such that: "SEND" + "MORE" = "MONEY" , 9567 + 1085 = 10652
    Example 2:

    Input: words = ["SIX","SEVEN","SEVEN"], result = "TWENTY"
    Output: true
    Explanation: Map 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4
    Such that: "SIX" + "SEVEN" + "SEVEN" = "TWENTY" , 650 + 68782 + 68782 = 138214
    Example 3:

    Input: words = ["THIS","IS","TOO"], result = "FUNNY"
    Output: true
    Example 4:

    Input: words = ["LEET","CODE"], result = "POINT"
    Output: false
     

    Constraints:

    2 <= words.length <= 5
    1 <= words[i].length, result.length <= 7
    words[i], result contains only upper case English letters.
    Number of different characters used on the expression is at most 10.


    给你一个方程,左边用 words 表示,右边用 result 表示。

    你需要根据以下规则检查方程是否可解:

    每个字符都会被解码成一位数字(0 - 9)。
    每对不同的字符必须映射到不同的数字。
    每个 words[i] 和 result 都会被解码成一个没有前导零的数字。
    左侧数字之和(words)等于右侧数字(result)。 
    如果方程可解,返回 True,否则返回 False。

    示例 1:

    输入:words = ["SEND","MORE"], result = "MONEY"
    输出:true
    解释:映射 'S'-> 9, 'E'->5, 'N'->6, 'D'->7, 'M'->1, 'O'->0, 'R'->8, 'Y'->'2'
    所以 "SEND" + "MORE" = "MONEY" , 9567 + 1085 = 10652
    示例 2:

    输入:words = ["SIX","SEVEN","SEVEN"], result = "TWENTY"
    输出:true
    解释:映射 'S'-> 6, 'I'->5, 'X'->0, 'E'->8, 'V'->7, 'N'->2, 'T'->1, 'W'->'3', 'Y'->4
    所以 "SIX" + "SEVEN" + "SEVEN" = "TWENTY" , 650 + 68782 + 68782 = 138214
    示例 3:

    输入:words = ["THIS","IS","TOO"], result = "FUNNY"
    输出:true
    示例 4:

    输入:words = ["LEET","CODE"], result = "POINT"
    输出:false
     

    提示:

    2 <= words.length <= 5
    1 <= words[i].length, results.length <= 7
    words[i], result 只含有大写英文字母
    表达式中使用的不同字符数最大为 10

  • 相关阅读:
    Java入门3.2---线程池
    Java入门3.1---多线程
    打开ppt报"powerpoint无法加载mathtype加载项"错误
    LATEX排版总结
    casbin 权限系统
    Go netpoll I/O 多路复用构建原生网络模型之源码深度解析
    使用winsw包装服务将nginx包装为Windows服务
    Node.js 的模块系统
    一文读懂 babel7 的配置文件加载逻辑
    vue-cli是什么?和 webpack是什么关系?
  • 原文地址:https://www.cnblogs.com/strengthen/p/12151686.html
Copyright © 2020-2023  润新知