My simple c++ solution


  • 0
    K
    class Solution {
     public:
    void rotate(vector<vector<int>>& matrix) {
        if(matrix.size()==0 || matrix.size()==1)return;
        int m=matrix.size(), n=matrix[0].size();
        for(int i=0; i < m/2 ; i++){
            for(int j=i+1; j < n-i; j++){
                int temp=matrix[i][j];
                //cout << matrix[i][j] << " replace by " << matrix[n-1-j][i] << endl;
                matrix[i][j]=matrix[n-1-j][i];
                
                matrix[n-j-1][i]=matrix[n-i-1][n-j-1];
                
                matrix[n-i-1][n-j-1]=matrix[j][n-i-1];
                matrix[j][n-i-1]=temp;
            }
        }
    }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.