Leetcode Note: Go - Decode the Message
Decode the Message - LeetCode
https://leetcode.com/problems/decode-the-message/
- Go 言語で取り組んだメモ
回答
Go 15 loc solution, 0ms - Decode the Message - LeetCode
https://leetcode.com/problems/decode-the-message/solutions/2555436/go-15-loc-solution-0ms/
func decodeMessage(key string, message string) string {
table := map[rune]byte{' ': ' '}
for _, c := range key {
if _, ok := table[c]; !ok {
table[c] = byte(len(table) - 1 + 'a')
}
}
var buffer bytes.Buffer
for _, c := range message {
buffer.WriteByte(table[c])
}
return buffer.String()
}