Leetcode Note: Go - Replace All Digits With Characters
Greatest Common Divisor of Strings - LeetCode
https://leetcode.com/problems/greatest-common-divisor-of-strings/
- Go 言語で取り組んだメモ
回答
Go simple solution - Replace All Digits with Characters - LeetCode
https://leetcode.com/problems/replace-all-digits-with-characters/solutions/2462013/go-simple-solution/
func replaceDigits(s string) string {
var result strings.Builder
for i := 0; i < len(s); i++ {
if i%2 == 1 {
result.WriteByte(s[i-1] + toInt(s[i]))
} else {
result.WriteByte(s[i])
}
}
return result.String()
}
func toInt(char byte) byte {
return char - '0'
}