mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
18 lines
279 B
Go
18 lines
279 B
Go
package leetcode
|
|
|
|
import "strings"
|
|
|
|
func reverseWords151(s string) string {
|
|
ss := strings.Fields(s)
|
|
reverse151(&ss, 0, len(ss)-1)
|
|
return strings.Join(ss, " ")
|
|
}
|
|
|
|
func reverse151(m *[]string, i int, j int) {
|
|
for i <= j {
|
|
(*m)[i], (*m)[j] = (*m)[j], (*m)[i]
|
|
i++
|
|
j--
|
|
}
|
|
}
|