Skip to content

Commit 863bc29

Browse files
authored
Merge pull request gzc426#11 from Syuan-Cheng/Syuan-Cheng-patch-8
Create syuan.md
2 parents eb996ea + 63b6e51 commit 863bc29

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

2018.12.2-leetcode557/syuan.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
##### 题目
2+
给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。
3+
4+
示例 1:
5+
6+
输入: "Let's take LeetCode contest"
7+
输出: "s'teL ekat edoCteeL tsetnoc"
8+
9+
注意:在字符串中,每个单词由单个空格分隔,并且字符串中不会有任何额外的空格。
10+
##### 代码
11+
12+
```
13+
public class Solution {
14+
public String reverseWords(String s) {
15+
16+
if(s == null){ return null;}
17+
18+
String[] strChar=s.split(" ");
19+
int size=strChar.length;
20+
//reverse every vocabulary
21+
String reverse="";
22+
for (int i=0; i<size; ++i) {
23+
strChar[i] = new StringBuilder(strChar[i]).reverse().toString();
24+
}
25+
//linking every vocabulary
26+
StringBuilder result = new StringBuilder();
27+
for (String st : strChar) {
28+
result.append(st + " ");
29+
}
30+
return result.toString().trim();
31+
}
32+
}
33+
```

0 commit comments

Comments
 (0)