Leetcode Note: Go - Capitalize the Title
Capitalize the Title - LeetCode
https://leetcode.com/problems/capitalize-the-title/
- Go 言語で取り組んだメモ
回答
Golang: 100% fast - Capitalize the Title - LeetCode
https://leetcode.com/problems/capitalize-the-title/solutions/3228807/golang-100-fast/
func capitalizeTitle(title string) string {
title = strings.ToLower(title)
v := strings.Split(title, " ")
for i := 0; i < len(v); i++ {
if len(v[i]) < 3 {
v[i] = strings.ToLower(v[i])
} else {
v[i] = strings.Title(v[i])
}
}
title = strings.Join(v, " ")
return title
}