20240502 Finished
This commit is contained in:
parent
7a201f1252
commit
e67955f9ac
|
@ -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;
|
42
src/problem/p48_rotate_image.rs
Normal file
42
src/problem/p48_rotate_image.rs
Normal 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() {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user