Skip to content

Commit 7012dc3

Browse files
authored
Update README_EN.md
1 parent b980326 commit 7012dc3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

solution/0000-0099/0054.Spiral Matrix/README_EN.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,46 @@ func spiralOrder(matrix [][]int) (ans []int) {
350350
}
351351
```
352352

353+
### **Rust**
354+
355+
```rust
356+
impl Solution {
357+
pub fn spiral_order(matrix: Vec<Vec<i32>>) -> Vec<i32> {
358+
let mut x1 = 0;
359+
let mut y1 = 0;
360+
let mut x2 = matrix.len() - 1;
361+
let mut y2 = matrix[0].len() - 1;
362+
let mut result = vec![];
363+
364+
while x1 <= x2 && y1 <= y2 {
365+
for j in y1..=y2 {
366+
result.push(matrix[x1][j]);
367+
}
368+
for i in x1 + 1..=x2 {
369+
result.push(matrix[i][y2]);
370+
}
371+
if x1 < x2 && y1 < y2 {
372+
for j in (y1..y2).rev() {
373+
result.push(matrix[x2][j]);
374+
}
375+
for i in (x1 + 1..x2).rev() {
376+
result.push(matrix[i][y1]);
377+
}
378+
}
379+
x1 += 1;
380+
y1 += 1;
381+
if x2 != 0 {
382+
x2 -= 1;
383+
}
384+
if y2 != 0 {
385+
y2 -= 1;
386+
}
387+
}
388+
return result;
389+
}
390+
}
391+
```
392+
353393
### **JavaScript**
354394

355395
```js

0 commit comments

Comments
 (0)