20240502 Finished

This commit is contained in:
jackfiled 2024-05-02 20:17:28 +08:00
parent 7a201f1252
commit e67955f9ac
2 changed files with 44 additions and 1 deletions

View File

@ -118,4 +118,5 @@ mod p209_minimum_size_subarray_sum;
mod p30_substring_with_concatenation_of_all_words;
mod p76_minimum_window_substring;
mod p36_valid_sudoku;
mod p54_spiral_matrix;
mod p54_spiral_matrix;
mod p48_rotate_image;

View File

@ -0,0 +1,42 @@
/**
* [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() {
}
}