Leetcode Note: Go - Check Whether Two Strings Are Almost Equivalent
Check Whether Two Strings are Almost Equivalent - LeetCode
https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/
- Go 言語で取り組んだメモ
回答
Two Golang Solutions - Check Whether Two Strings are Almost Equivalent - LeetCode
https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/solutions/1579700/two-golang-solutions/
func checkAlmostEquivalent(word1 string, word2 string) bool {
letters := make([]int, 26)
for i := 0; i < len(word1); i++ {
letters[int(word1[i] - 'a')]++
letters[int(word2[i] - 'a')]--
}
for _, a := range letters {
if a < -3 || a > 3 { return false }
}
return true
}