Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite325e40

Browse files
[LEET-557] add 557
1 parentf36196a commite325e40

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

‎leetcode-algorithms/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
##Algorithms
44
| # | Title | Solutions | Time | Space | Difficulty | Tag | Notes
55
|-----|----------------|---------------|---------------|---------------|-------------|--------------|-----
6+
|557|[Reverse Words in a String III](https://leetcode.com/problems/reverse-words-in-a-string-iii/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/ReverseWordsinaStringIII.java) | O(n) |O(n) | Easy | String
67
|548|[Split Array with Equal Sum](https://leetcode.com/problems/split-array-with-equal-sum/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/SplitArraywithEqualSum.java) | O(n^2) |O(1) | Medium | Array
78
|547|[Friend Circles](https://leetcode.com/problems/friend-circles/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/FriendCircles.java) | O(n^2) |O(n) | Medium | Union Find
89
|545|[Boundary of Binary Tree](https://leetcode.com/problems/boundary-of-binary-tree/)|[Solution](../../master/leetcode-algorithms/src/main/java/com/stevesun/solutions/BoundaryofBinaryTree.java) | O(n) |O(n) | Medium | Recursion
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
packagecom.stevesun.solutions;
2+
3+
/**
4+
* 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.
5+
6+
Example 1:
7+
Input: "Let's take LeetCode contest"
8+
Output: "s'teL ekat edoCteeL tsetnoc"
9+
Note: In the string, each word is separated by single space and there will not be any extra space in the string.
10+
*/
11+
publicclassReverseWordsinaStringIII {
12+
13+
publicStringreverseWords(Strings) {
14+
StringBuilderstringBuilder =newStringBuilder();
15+
StringBuildersbUtils =newStringBuilder();
16+
for (Stringword :s.split(" ")) {
17+
sbUtils.setLength(0);
18+
sbUtils.append(word);
19+
stringBuilder.append(sbUtils.reverse().toString());
20+
stringBuilder.append(" ");
21+
}
22+
stringBuilder.setLength(stringBuilder.length()-1);
23+
returnstringBuilder.toString();
24+
}
25+
26+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp