```
class Solution {
public:
void rotate(vector<vector<int> > &matrix) {
if (matrix.size() <= 0) return;
int n = matrix.size();
int level, s, e, j;
for (level = 1; level <= n/2; level++)
{
s = level - 1;
e = n - 1 - level;
for (j = s; j <= e; j++)
{
int temp = matrix[level-1][j];
matrix[level-1][j] = matrix[e+level-j][s];
matrix[e+level-j][s] = matrix[e-s+level][e-j+s+1];
matrix[e-s+level][e-j+s+1] = matrix[level-1+j-s][e+1];
matrix[level-1+j-s][e+1] = temp;
}
}
}
};
```