Skip to content

Commit 4c31939

Browse files
committed
feat: add rust solution to lc problem: No.0006
No.0006.ZigZag Conversion
1 parent 8d1bcf1 commit 4c31939

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

solution/0000-0099/0006.ZigZag Conversion/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ impl Solution {
291291
}
292292
```
293293

294+
```rust
295+
impl Solution {
296+
pub fn convert(s: String, num_rows: i32) -> String {
297+
let num_rows = num_rows as usize;
298+
let mut rows = vec![String::new(); num_rows];
299+
let iter = (0..num_rows).chain((1..num_rows - 1).rev()).cycle();
300+
iter.zip(s.chars()).for_each(|(i, c)| rows[i].push(c));
301+
rows.into_iter().collect()
302+
}
303+
}
304+
```
305+
294306
### **...**
295307

296308
```

solution/0000-0099/0006.ZigZag Conversion/README_EN.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,18 @@ impl Solution {
285285
}
286286
```
287287

288+
```rust
289+
impl Solution {
290+
pub fn convert(s: String, num_rows: i32) -> String {
291+
let num_rows = num_rows as usize;
292+
let mut rows = vec![String::new(); num_rows];
293+
let iter = (0..num_rows).chain((1..num_rows - 1).rev()).cycle();
294+
iter.zip(s.chars()).for_each(|(i, c)| rows[i].push(c));
295+
rows.into_iter().collect()
296+
}
297+
}
298+
```
299+
288300
### **...**
289301

290302
```

0 commit comments

Comments
 (0)