Leetcode Note: Go - Check if Word Equals Summation of Two Words

Check if Word Equals Summation of Two Words - LeetCode
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/

  • Go 言語で取り組んだメモ

回答

Go golang clean solution - Check if Word Equals Summation of Two Words - LeetCode
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/solutions/1242130/go-golang-clean-solution/

func isSumEqual(firstWord string, secondWord string, targetWord string) bool {
    return helper(firstWord) + helper(secondWord) == helper(targetWord)
}

func helper(s string) int {
    ans := 0
    for _, c := range s { ans = ans * 10 + int(c - 'a') }
    return ans
}