LeetCode 557. 反转字符串中的单词 III
题目描述
思路分析
思路描述
参考代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func reverseWords(s string) string {
words := strings.Fields(s)
for i := 0; i < len(words); i++ {
words[i] = reverseString(words[i])
}
return strings.Join(words, " ")
}
func reverseString(s string) string {
runes := []rune(s)
length := len(runes)
for i, j := 0, length-1; i < j; i, j = i+1, j-1 {
runes[i], runes[j] = runes[j], runes[i]
}
return string(runes)
}
1
write your code here
CC BY-NC-SA 4.0
许可协议,转载请注明出处!
本博客所有文章除特别声明外,均采用