Skip to content

Commit ace0c72

Browse files
Create 我爱吃瓜子.md
2018-11-27 leetcode151
1 parent 5bb76b1 commit ace0c72

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#leetcode151
2+
```
3+
public class Solution {
4+
public String reverseWords(String s) {
5+
if(s!=null&&"".equals(s)){
6+
return s;
7+
}else if(s!=null){
8+
String[] ss=s.split(" ");
9+
if(ss.length==0){
10+
return "";
11+
}else{
12+
String result="";
13+
for(int i=ss.length-1;i>=0;i--){
14+
if(i==ss.length-1){
15+
if(!ss[i].trim().equals("")){
16+
result+=ss[i].trim();
17+
}
18+
19+
}else{
20+
if(!ss[i].trim().equals("")){
21+
result+=" "+ss[i].trim();
22+
}
23+
}
24+
25+
}
26+
return result;
27+
}
28+
}
29+
return s;
30+
}
31+
}
32+
```

0 commit comments

Comments
 (0)