We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5f44baa + 8afa6c0 commit ffc763aCopy full SHA for ffc763a
2018.11.28-leetcode151/。。。.md
@@ -0,0 +1,27 @@
1
+public String reverseWords(String s) {
2
+ int i = s.length()-1,wordRight=-1;
3
+ StringBuilder builder = new StringBuilder();
4
+ while (i >= 0){
5
+ if (s.charAt(i) == ' '){
6
+ if (wordRight!=-1){
7
+ if (builder.length()!=0){
8
+ builder.append(' ');
9
+ }
10
+ builder.append(s.substring(i+1,wordRight+1));
11
+ wordRight=-1;
12
13
+ i--;
14
+ continue;
15
16
+ if (wordRight==-1)wordRight = i;
17
18
19
+ //添加最后一个单词
20
21
22
23
24
25
26
+ return builder.toString();
27
0 commit comments