add new solutions
This commit is contained in:
parent
9c2c959a9b
commit
9a10695e8c
29 changed files with 1074 additions and 2 deletions
19
solutions/1/q151/solution.go
Normal file
19
solutions/1/q151/solution.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package q151
|
||||
|
||||
import "strings"
|
||||
|
||||
func reverseWords(s string) string {
|
||||
b := strings.Builder{}
|
||||
fields := strings.Fields(s)
|
||||
if len(fields) > 0 {
|
||||
b.WriteString(fields[len(fields)-1])
|
||||
}
|
||||
for i := len(fields) - 2; i >= 0; i-- {
|
||||
b.WriteByte(' ')
|
||||
b.WriteString(fields[i])
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
var _ = reverseWords
|
||||
Loading…
Add table
Add a link
Reference in a new issue