输入:firstWord = “acb”, secondWord = “cba”, targetWord = “cdb”
输出:true
解释:
firstWord 的数值为 “acb” -> “021” -> 21
secondWord 的数值为 “cba” -> “210” -> 210
targetWord 的数值为 “cdb” -> “231” -> 231
由于 21 + 210 == 231 ,返回 true
func isSumEqual(firstWord string, secondWord string, targetWord string) bool {
decode := func(s string) int {
ans := 0
for _, v := range s {
ans *= 10
ans += int(v-'a')
}
return ans
}
return decode(firstWord) +decode(secondWord) == decode(targetWord)
}