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
This repository was archived by the owner on Apr 27, 2025. It is now read-only.

Commit433ab83

Browse files
committed
# 557. Reverse Words in a String III
1 parent2caf2df commit433ab83

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#557. Reverse Words in a String III
2+
3+
###2017-04-09
4+
5+
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.
6+
7+
**Example 1:**
8+
9+
```
10+
Input: "Let's take LeetCode contest"
11+
Output: "s'teL ekat edoCteeL tsetnoc"
12+
13+
```
14+
15+
**Note:** In the string, each word is separated by single space and there will not be any extra space in the string.
16+
17+
18+
19+
#Solution
20+
21+
```swift
22+
classSolution {
23+
funcreverseWords(_s:String)->String {
24+
return s.components(separatedBy:"")
25+
.flatMap({$0.characters.reversed().reduce("", {$0+$1.description})})
26+
.reduce("", {$0.isEmpty?$1:"\($0)\($1)" })
27+
28+
}
29+
}
30+
```
31+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp