Skip to content

Commit 15ff440

Browse files
committed
feat: add solutions to lc problem: No.0557
No.0557.Reverse Words in a String III
1 parent 6c44bdf commit 15ff440

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

solution/0500-0599/0557.Reverse Words in a String III/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,36 @@ func reverseWords(s string) string {
9696
}
9797
```
9898

99+
### **TypeScript**
100+
101+
```ts
102+
function reverseWords(s: string): string {
103+
return s
104+
.split(/\s+/)
105+
.map(str => {
106+
let res = '';
107+
for (const c of str) {
108+
res = c + res;
109+
}
110+
return res;
111+
})
112+
.join(' ');
113+
}
114+
```
115+
116+
### **Rust**
117+
118+
```rust
119+
impl Solution {
120+
pub fn reverse_words(s: String) -> String {
121+
s.split(' ')
122+
.map(|s| s.chars().rev().collect::<String>())
123+
.collect::<Vec<_>>()
124+
.join(" ")
125+
}
126+
}
127+
```
128+
99129
### **...**
100130

101131
```

solution/0500-0599/0557.Reverse Words in a String III/README_EN.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,36 @@ func reverseWords(s string) string {
9191
}
9292
```
9393

94+
### **TypeScript**
95+
96+
```ts
97+
function reverseWords(s: string): string {
98+
return s
99+
.split(/\s+/)
100+
.map(str => {
101+
let res = '';
102+
for (const c of str) {
103+
res = c + res;
104+
}
105+
return res;
106+
})
107+
.join(' ');
108+
}
109+
```
110+
111+
### **Rust**
112+
113+
```rust
114+
impl Solution {
115+
pub fn reverse_words(s: String) -> String {
116+
s.split(' ')
117+
.map(|s| s.chars().rev().collect::<String>())
118+
.collect::<Vec<_>>()
119+
.join(" ")
120+
}
121+
}
122+
```
123+
94124
### **...**
95125

96126
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
impl Solution {
2+
pub fn reverse_words(s: String) -> String {
3+
s.split(' ')
4+
.map(|s| s.chars().rev().collect::<String>())
5+
.collect::<Vec<_>>()
6+
.join(" ")
7+
}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function reverseWords(s: string): string {
2+
return s
3+
.split(/\s+/)
4+
.map(str => {
5+
let res = '';
6+
for (const c of str) {
7+
res = c + res;
8+
}
9+
return res;
10+
})
11+
.join(' ');
12+
}

0 commit comments

Comments
 (0)