C++ inplace solution


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

Log in to reply
 

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