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(); + } + } +}