Common method but 3ms C++ solution


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

Log in to reply
 

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