leetcode 48 rotation matrix

Given an n × n two-dimensional matrix matrix representing an image. Please rotate the image 90 degrees clockwise.

You have to rotate the image in place, which means you need to directly modify the input 2D matrix. Please don't use another matrix to rotate the image.

class Solution {
public:
    void rotate(vector<vector<int>>& matrix) {
        auto temp_matrix= matrix;
        int n=matrix.size();
        for(int i=0;i<matrix.size();i++)
        {
            for(int j=0;j< matrix[i].size();j++)
            {
                temp_matrix[j][n-1-i]=matrix[i][j];
            }
        }
        matrix=temp_matrix;
    }
};

Guess you like

Origin blog.csdn.net/Doubao93/article/details/122475291