Skip to content

Commit d283e51

Browse files
authored
Merge pull request gzc426#158 from PYTWSW/master
create WhiteNight.md
2 parents c417eb5 + 949a80f commit d283e51

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

2018.11.28-leetcode151/WhiteNight.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```java
2+
/**
3+
* 翻转字符串里面的单词
4+
*
5+
*/
6+
public class S2 {
7+
public String reverseWords(String s) {
8+
if (s == null || s.length() == 0)
9+
return "";
10+
11+
String[] string = s.split(" ");
12+
String res = "";
13+
14+
for (int i = string.length - 1; i >= 0; i--) {
15+
if (!string[i].equals("")){
16+
if (res.length() > 0){
17+
res += " ";
18+
}
19+
res += string[i];
20+
}
21+
}
22+
23+
return res;
24+
}
25+
26+
public static void main(String[] args) {
27+
S2 s = new S2();
28+
String string = "the sky is blue";
29+
String res = s.reverseWords(string);
30+
System.out.println(res);
31+
}
32+
}
33+
```

0 commit comments

Comments
 (0)