-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution557.java
More file actions
43 lines (38 loc) · 1.03 KB
/
Copy pathSolution557.java
File metadata and controls
43 lines (38 loc) · 1.03 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @Title: Solution557.java——
* @Package EasyCode_02
* @Description: TODO
* @author msdumin@gmail.com
* @date 2019年4月3日 下午8:54:30
* @version V1.0
*/
package EasyCode_02;
/**
* @ClassName: Solution557——反转字符串的单词
* @Description: TODO
* 输入: "Let's take LeetCode contest"
输出: "s'teL ekat edoCteeL tsetnoc"
* @author msdumin@gmail.com
* @date 2019年4月3日 下午8:54:30
*/
public class Solution557 {
public static String reverseWords(String s) {
String[] tmp = s.split(" ");
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i < tmp.length ; i ++){
tmp[i] = new StringBuilder(tmp[i]).reverse().toString();
if(i == tmp.length - 1)
sb.append(tmp[i]);
else{
sb.append(tmp[i]).append(" ");
}
}
return sb.toString();
}
/* public static String reverseWords(String s) {
}*/
public static void main(String[] args) {
String s = "Let's take LeetCode contest";
System.out.println(reverseWords(s));
}
}