3ms Easy c++ O(1)space


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

Log in to reply
 

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