From 40258a8b600bb062d5f1956d467be7b1a3d6f8dc Mon Sep 17 00:00:00 2001 From: Dale Seo <5466341+DaleSeo@users.noreply.github.com> Date: Sun, 14 Jun 2026 20:43:45 -0400 Subject: [PATCH] rotate-image --- rotate-image/DaleSeo.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 rotate-image/DaleSeo.rs diff --git a/rotate-image/DaleSeo.rs b/rotate-image/DaleSeo.rs new file mode 100644 index 000000000..cf5235031 --- /dev/null +++ b/rotate-image/DaleSeo.rs @@ -0,0 +1,19 @@ +// TC: O(n^2) +// SC: O(1) +impl Solution { + pub fn rotate(matrix: &mut Vec>) { + let n = matrix.len(); + + for i in 0..n { + for j in (i + 1)..n { + let tmp = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = tmp; + } + } + + for row in matrix.iter_mut() { + row.reverse(); + } + } +}