Rotate Image

Description:

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?

 

Code:

 1     void rotate(vector<vector<int>>& matrix) {

 2         int n = matrix.size();

 3         vector< vector<int> > temp(matrix);

 4         for (int i = 0; i < n; ++i)

 5         {

 6             for (int j = 0; j < n; ++j)

 7             {

 8                 matrix[i][j] = temp[n-1-j][i];

 9             }

10         }

11     }

 

你可能感兴趣的:(image)