Leetcode Note: Go - Delete Charactoers to Make Fancy String
Delete Characters to Make Fancy String - LeetCode
https://leetcode.com/problems/delete-characters-to-make-fancy-string/
- Go 言語で取り組んだメモ
回答
Go(lang) Solution - Delete Characters to Make Fancy String - LeetCode
https://leetcode.com/problems/delete-characters-to-make-fancy-string/solutions/1429683/go-lang-solution/
func makeFancyString(s string) string {
ans := []byte{s[0]}
count := 1
for i := 1; i < len(s); i++ {
if s[i] == s[i - 1] {
count++
if count < 3 {
ans = append(ans, s[i])
}
} else{
count = 1
ans = append(ans, s[i])
}
}
return string(ans)
}