Leetcode Note: Go - Reverse Prefix of Word
Reverse Prefix of Word - LeetCode
https://leetcode.com/problems/reverse-prefix-of-word/
- Go 言語で取り組んだメモ
回答
Simple Golang Solution - Reverse Prefix of Word - LeetCode
https://leetcode.com/problems/reverse-prefix-of-word/solutions/1461548/simple-golang-solution/
func reversePrefix(word string, ch byte) string {
s := ""
for i, letter := range word {
s = string(letter) + s
if letter == rune(ch) {
return s + word[i + 1 :]
}
}
return word
}