matrix가 주어지면 space O(1)으로 90도 시계방향으로 회전한다
/*
* clockwise rotate
* first reverse up to down, then swap the symmetry
* 1 2 3 7 8 9 7 4 1
* 4 5 6 => 4 5 6 => 8 5 2
* 7 8 9 1 2 3 9 6 3
*/
vector<vector<int>> solution(vector<vector<int>> a) {
int n = a.size();
int m = a[0].size();
// reverse top down
for (int i = 0; i < n / 2; i++) {
for(int j = 0; j < m; j++)
swap(a[i][j], a[a.size() - 1 - i][j]);
}
// swap the symmetry
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
swap(a[i][j], a[j][i]);
}
}
return a;
}