Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions solution/0557.Reverse Words in a String III/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Reverse Words in a String III

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.

## Example 1:
```
Input: "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
```
13 changes: 13 additions & 0 deletions solution/0557.Reverse Words in a String III/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public String reverseWords(String s) {
String flag = " ";
StringBuilder result = new StringBuilder();
for (String temp : s.split(flag)) {
for (int i = temp.length() - 1; i >= 0; i--) {
result.append(temp.charAt(i));
}
result.append(flag);
}
return result.toString().substring(0, s.length());
}
}