Rotate Image

You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

Follow up:
Could you do this in-place?

代码;

 1     void rotate(vector<vector<int> > &matrix) {
 2         // Start typing your C/C++ solution below
 3         // DO NOT write int main() function
 4         int n = matrix[0].size();
 5         int tmp;
 6         for(int i = 0; i <n/2; i++){
 7             for(int j = i; j < n-1-i; j++){
 8                 tmp = matrix[i][j];
 9                 matrix[i][j] = matrix[n-1-j][i];
10                 matrix[n-1-j][i] = matrix[n-1-i][n-1-j];
11                 matrix[n-1-i][n-1-j] = matrix[j][n-1-i];
12                 matrix[j][n-1-i] = tmp;
13             }
14         }
15     }
原文地址:https://www.cnblogs.com/waruzhi/p/3409910.html