File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
solution/0557.Reverse Words in a String III Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Reverse Words in a String III
2
+
3
+ Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
4
+
5
+ ## Example 1:
6
+ ```
7
+ Input: "Let's take LeetCode contest"
8
+ Output: "s'teL ekat edoCteeL tsetnoc"
9
+ ```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public String reverseWords (String s ) {
3
+ String flag = " " ;
4
+ StringBuilder result = new StringBuilder ();
5
+ for (String temp : s .split (flag )) {
6
+ for (int i = temp .length () - 1 ; i >= 0 ; i --) {
7
+ result .append (temp .charAt (i ));
8
+ }
9
+ result .append (flag );
10
+ }
11
+ return result .toString ().substring (0 , s .length ());
12
+ }
13
+ }
You can’t perform that action at this time.
0 commit comments