mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-25 12:14:26 +08:00
规范格式
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func reverseWords(s string) string {
|
||||
ss := strings.Split(s, " ")
|
||||
for i, s := range ss {
|
||||
ss[i] = revers(s)
|
||||
}
|
||||
return strings.Join(ss, " ")
|
||||
}
|
||||
|
||||
func revers(s string) string {
|
||||
bytes := []byte(s)
|
||||
i, j := 0, len(bytes)-1
|
||||
for i < j {
|
||||
bytes[i], bytes[j] = bytes[j], bytes[i]
|
||||
i++
|
||||
j--
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
Reference in New Issue
Block a user