4ms c++


  • 0
    B
    class Solution {
    public:
        void rotate(vector< vector<int> >& matrix) {
            int n=matrix.size()-1;
            int m=n/2;
            for(int i=0;i<=n;i++)
                for(int j=0;j<=i;j++)
                {
                    int tmp = matrix[i][j];
                    matrix[i][j]=matrix[j][i];
                    matrix[j][i]=tmp;
                }
            for(int i=0;i<=n;i++)
                for(int j=0;j<=m;j++)
                {
                    int tmp = matrix[i][j];
                    matrix[i][j] = matrix[i][n-j];
                    matrix[i][n-j]=tmp;
                }
        }
    };
    

Log in to reply
 

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