Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 81b6c58

Browse files
author
Openset
committed
Update: reverse_words_in_a_string_iii
1 parent 0687284 commit 81b6c58

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package reverse_words_in_a_string_iii
22

33
func reverseWords(s string) string {
4-
ws, pre, l := []byte(s+" "), 0, len(s)
5-
for cur, c := range ws {
4+
ss, pre, l := []byte(s+" "), 0, len(s)
5+
for cur, c := range ss {
66
if c == ' ' {
7-
word := ws[pre:cur]
8-
for i, j := 0, len(word)-1; i < j; i, j = i+1, j-1 {
9-
word[i], word[j] = word[j], word[i]
7+
ws := ss[pre:cur]
8+
for i, j := 0, len(ws)-1; i < j; i, j = i+1, j-1 {
9+
ws[i], ws[j] = ws[j], ws[i]
1010
}
1111
pre = cur + 1
1212
}
1313
}
14-
return string(ws[:l])
14+
return string(ss[:l])
1515
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /