Leetcode Note Go Decrypt String From Alphabet to Integer Mapping
Decrypt String from Alphabet to Integer Mapping - LeetCode
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/
- Go 言語で取り組んだメモ
回答
Go O(n) solution using bytes.Buffer - Decrypt String from Alphabet to Integer Mapping - LeetCode
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/solutions/774889/go-o-n-solution-using-bytes-buffer/
func freqAlphabets(s string) string {
var buf bytes.Buffer
for i, ch := range s {
if ch == '#' {
buf.Truncate(buf.Len() - 2)
d, _ := strconv.Atoi(s[i-2 : i])
buf.WriteString(string(96 + d))
} else {
buf.WriteRune(ch + 48)
}
}
return buf.String()
}