码迷,mamicode.com
首页 > 其他好文 > 详细

Rotate Image

时间:2015-06-14 10:53:39      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

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     }

 

Rotate Image

标签:

原文地址:http://www.cnblogs.com/happygirl-zjj/p/4574627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!