You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
340 B
20 lines
340 B
2 years ago
|
package reversewords
|
||
|
|
||
|
import "strings"
|
||
|
|
||
|
func reverse(s string) string {
|
||
|
result := make([]rune, len(s))
|
||
|
for i, v := range s {
|
||
|
result[len(result)-i-1] = v
|
||
|
}
|
||
|
return string(result)
|
||
|
}
|
||
|
|
||
|
func ReverseWords(s string) string {
|
||
|
words := strings.Fields(s)
|
||
|
for i, v := range words {
|
||
|
words[i] = reverse(v)
|
||
|
}
|
||
|
return strings.Join(words, " ")
|
||
|
}
|