-
Notifications
You must be signed in to change notification settings - Fork 0
/
557.go
45 lines (36 loc) · 732 Bytes
/
557.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
# ------------------------------ #
# #
# version 0.0.1 #
# #
# Aleksiej Ostrowski, 2023 #
# #
# https://aleksiej.com #
# #
# ------------------------------ #
*/
package main
import (
"fmt"
"strings"
)
func reverseWords(s string) string {
res := []string{}
buf := ""
for _, el := range s {
if el != ' ' {
buf = string(el) + buf
} else {
res = append(res, buf)
buf = ""
}
}
if buf != "" {
res = append(res, buf)
}
return strings.Join(res, " ")
}
func main() {
fmt.Println(reverseWords("Let's take LeetCode contest"))
fmt.Println("ok")
}