From b980326c5765947ba942e6c0d7ad0e088efd16fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sarvex=20=E2=98=A0=20Jatasra?= Date: Thu, 21 Dec 2023 08:06:05 +0530 Subject: [PATCH 1/4] Create Solution.rs --- .../0000-0099/0054.Spiral Matrix/Solution.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 solution/0000-0099/0054.Spiral Matrix/Solution.rs diff --git a/solution/0000-0099/0054.Spiral Matrix/Solution.rs b/solution/0000-0099/0054.Spiral Matrix/Solution.rs new file mode 100644 index 0000000000000..04eb1e7c3e013 --- /dev/null +++ b/solution/0000-0099/0054.Spiral Matrix/Solution.rs @@ -0,0 +1,35 @@ +impl Solution { + pub fn spiral_order(matrix: Vec>) -> Vec { + let mut x1 = 0; + let mut y1 = 0; + let mut x2 = matrix.len() - 1; + let mut y2 = matrix[0].len() - 1; + let mut result = vec![]; + + while x1 <= x2 && y1 <= y2 { + for j in y1..=y2 { + result.push(matrix[x1][j]); + } + for i in x1 + 1..=x2 { + result.push(matrix[i][y2]); + } + if x1 < x2 && y1 < y2 { + for j in (y1..y2).rev() { + result.push(matrix[x2][j]); + } + for i in (x1 + 1..x2).rev() { + result.push(matrix[i][y1]); + } + } + x1 += 1; + y1 += 1; + if x2 != 0 { + x2 -= 1; + } + if y2 != 0 { + y2 -= 1; + } + } + return result; + } +} From 7012dc3da906904e89e0884e645fd4876339c083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sarvex=20=E2=98=A0=20Jatasra?= Date: Thu, 21 Dec 2023 08:08:34 +0530 Subject: [PATCH 2/4] Update README_EN.md --- .../0000-0099/0054.Spiral Matrix/README_EN.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/solution/0000-0099/0054.Spiral Matrix/README_EN.md b/solution/0000-0099/0054.Spiral Matrix/README_EN.md index 2806b758b8bbf..768d4a2a0c47f 100644 --- a/solution/0000-0099/0054.Spiral Matrix/README_EN.md +++ b/solution/0000-0099/0054.Spiral Matrix/README_EN.md @@ -350,6 +350,46 @@ func spiralOrder(matrix [][]int) (ans []int) { } ``` +### **Rust** + +```rust +impl Solution { + pub fn spiral_order(matrix: Vec>) -> Vec { + let mut x1 = 0; + let mut y1 = 0; + let mut x2 = matrix.len() - 1; + let mut y2 = matrix[0].len() - 1; + let mut result = vec![]; + + while x1 <= x2 && y1 <= y2 { + for j in y1..=y2 { + result.push(matrix[x1][j]); + } + for i in x1 + 1..=x2 { + result.push(matrix[i][y2]); + } + if x1 < x2 && y1 < y2 { + for j in (y1..y2).rev() { + result.push(matrix[x2][j]); + } + for i in (x1 + 1..x2).rev() { + result.push(matrix[i][y1]); + } + } + x1 += 1; + y1 += 1; + if x2 != 0 { + x2 -= 1; + } + if y2 != 0 { + y2 -= 1; + } + } + return result; + } +} +``` + ### **JavaScript** ```js From 735681e7c7c9b8eb7ae670f283bcb55101b742c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sarvex=20=E2=98=A0=20Jatasra?= Date: Thu, 21 Dec 2023 08:09:06 +0530 Subject: [PATCH 3/4] Update README.md --- .../0000-0099/0054.Spiral Matrix/README.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/solution/0000-0099/0054.Spiral Matrix/README.md b/solution/0000-0099/0054.Spiral Matrix/README.md index 55bd25080ee84..d2023217ad7ca 100644 --- a/solution/0000-0099/0054.Spiral Matrix/README.md +++ b/solution/0000-0099/0054.Spiral Matrix/README.md @@ -360,6 +360,46 @@ func spiralOrder(matrix [][]int) (ans []int) { } ``` +### **Rust** + +```rust +impl Solution { + pub fn spiral_order(matrix: Vec>) -> Vec { + let mut x1 = 0; + let mut y1 = 0; + let mut x2 = matrix.len() - 1; + let mut y2 = matrix[0].len() - 1; + let mut result = vec![]; + + while x1 <= x2 && y1 <= y2 { + for j in y1..=y2 { + result.push(matrix[x1][j]); + } + for i in x1 + 1..=x2 { + result.push(matrix[i][y2]); + } + if x1 < x2 && y1 < y2 { + for j in (y1..y2).rev() { + result.push(matrix[x2][j]); + } + for i in (x1 + 1..x2).rev() { + result.push(matrix[i][y1]); + } + } + x1 += 1; + y1 += 1; + if x2 != 0 { + x2 -= 1; + } + if y2 != 0 { + y2 -= 1; + } + } + return result; + } +} +``` + ### **JavaScript** ```js From 1b73bf51ac50e4d323e827ae132873d6e3e9fbb3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:53:53 +0000 Subject: [PATCH 4/4] chore(deps): bump black from 23.3.0 to 24.3.0 Bumps [black](https://github.com/psf/black) from 23.3.0 to 24.3.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/23.3.0...24.3.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ef7a0bc088e95..ce8543ead80ea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -black==23.3.0 +black==24.3.0 Requests==2.31.0 sortedcontainers==2.4.0 urllib3==1.26.18