wordpress更换网站logo,全栈工程师是做网站吗,企业网网页,口碑好的江苏网站建设文章目录1. 题目2. 解题1. 题目
字母的 字母值 取决于字母在字母表中的位置#xff0c;从 0 开始 计数。即#xff0c;a - 0、b - 1、c - 2#xff0c;以此类推。
对某个由小写字母组成的字符串 s 而言#xff0c;其 数值 就等于将 s 中每个字母的 字母值 按…
文章目录1. 题目2. 解题1. 题目
字母的 字母值 取决于字母在字母表中的位置从 0 开始 计数。即a - 0、b - 1、c - 2以此类推。
对某个由小写字母组成的字符串 s 而言其 数值 就等于将 s 中每个字母的 字母值 按顺序 连接 并 转换 成对应整数。
例如s acb 依次连接每个字母的字母值可以得到 021 转换为整数得到 21 。
给你三个字符串 firstWord、secondWord 和 targetWord 每个字符串都由从 a 到 j 含 ‘a’ 和 ‘j’ 的小写英文字母组成。
如果 firstWord 和 secondWord 的 数值之和 等于 targetWord 的数值返回 true 否则返回 false 。
示例 1
输入firstWord acb, secondWord cba, targetWord cdb
输出true
解释
firstWord 的数值为 acb - 021 - 21
secondWord 的数值为 cba - 210 - 210
targetWord 的数值为 cdb - 231 - 231
由于 21 210 231 返回 true示例 2
输入firstWord aaa, secondWord a, targetWord aab
输出false
解释
firstWord 的数值为 aaa - 000 - 0
secondWord 的数值为 a - 0 - 0
targetWord 的数值为 aab - 001 - 1
由于 0 0 ! 1 返回 false示例 3
输入firstWord aaa, secondWord a, targetWord aaaa
输出true
解释
firstWord 的数值为 aaa - 000 - 0
secondWord 的数值为 a - 0 - 0
targetWord 的数值为 aaaa - 0000 - 0
由于 0 0 0 返回 true提示
1 firstWord.length, secondWord.length, targetWord.length 8
firstWord、secondWord 和 targetWord 仅由从 a 到 j 含 a 和 j 的小写英文字母组成。来源力扣LeetCode 链接https://leetcode-cn.com/problems/check-if-word-equals-summation-of-two-words 著作权归领扣网络所有。商业转载请联系官方授权非商业转载请注明出处。 2. 解题
遍历字符串计算其整数值
class Solution {
public:bool isSumEqual(string firstWord, string secondWord, string targetWord) {int a getnum(firstWord);int b getnum(secondWord);int c getnum(targetWord);return ab c;}int getnum(string s){int num 0;for(auto c : s){num num*10(c-a);}return num;}
};0 ms 5.8 MB C 我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号Michael阿明一起加油、一起学习进步