forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseWords.java
More file actions
25 lines (24 loc) · 703 Bytes
/
ReverseWords.java
File metadata and controls
25 lines (24 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package LeetCode;/**
* @Classname ReverseWords
* @Description TODO
* @Date 19-2-27 下午1:55
* @Created by mao<tianmao818@qq.com>
*/
public class ReverseWords {
public String reverseWords(String s) {
s=s.trim();
String [] arrs=s.split("\\s+");
String result="";
System.out.println(arrs.length);
for(int i=arrs.length-1;i>0;i--){
System.out.println(arrs[i]);
result+=(arrs[i]+" ");
}
result+=arrs[0];
return result;
}
public static void main(String[] args){
ReverseWords reverseWords=new ReverseWords();
System.out.println(reverseWords.reverseWords(" hello world! "));
}
}