MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / rotate

Method rotate

48. Rotate Image/src/main.rs:21–42  ·  view source on GitHub ↗
(matrix: &mut Vec<Vec<i32>>)

Source from the content-addressed store, hash-verified

19
20impl Solution {
21 pub fn rotate(matrix: &mut Vec<Vec<i32>>) {
22 let mut dimension = matrix.len();
23 let mut offset = 0;
24 while dimension > 1 {
25 let buflen = matrix.len() - 1 - offset * 2;
26 let mut buf: Vec<i32> = Vec::with_capacity(buflen);
27 for i in 0..buflen {
28 buf.push(matrix[offset][offset + i]);
29 }
30 println!("buf = {:#?}", buf);
31 // rotate
32 for i in 0..buflen {
33 matrix[offset + 0] [offset + i] = matrix[offset + buflen - i][offset + 0];
34 matrix[offset + buflen - i][offset + 0] = matrix[offset + buflen] [offset + buflen - i];
35 matrix[offset + buflen] [offset + buflen - i]= matrix[offset + i] [offset + buflen];
36 matrix[offset + i] [offset + buflen] = buf[i];
37 }
38 dimension -= 2;
39 offset += 1;
40 println!("matrix = {:?}", matrix);
41 }
42 }
43}
44
45#[cfg(test)]

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected