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