Leetcode Note: Go - Truncate Sentence
Truncate Sentence - LeetCode
https://leetcode.com/problems/truncate-sentence/
- Go 言語で取り組んだメモ
回答
Golang one liner with a quick explanation - Truncate Sentence - LeetCode
https://leetcode.com/problems/truncate-sentence/solutions/1207984/golang-one-liner-with-a-quick-explanation/
func truncateSentence(s string, k int) string {
arr := strings.Split(s, " ")
return strings.Join(arr[:k], " ")
}