leetcode/src/problem/p48_rotate_image.rs
2024-05-02 20:17:28 +08:00

43 lines
782 B
Rust

/**
* [48] Rotate Image
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn rotate(matrix: &mut Vec<Vec<i32>>) {
let n = matrix.len();
// 首先上下水平翻转
for i in (0..n / 2) {
for j in 0..n {
let t = matrix[i][j];
matrix[i][j] = matrix[n - i - 1][j];
matrix[n - i - 1][j] = t;
}
}
// 对角线翻转
for i in (0..n) {
for j in (0..i) {
let t = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = t;
}
}
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_48() {
}
}