C++ easy to understand solution

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

Log in to reply

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