1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { public: vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n) { for (int i = 0; i < n / 2; ++i) { for (int j = 0; j < n; ++j) { swap(mat[i][j], mat[n - 1 - i][j]); } }
for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { swap(mat[i][j], mat[j][i]); } }
return mat; } };
|