首页 > 其他 > 详细

LeetCode Rotate Image (模拟)

时间:2015-11-04 21:14:25      阅读:242      评论:0      收藏:0      [点我收藏+]

 

 

 

题意:

  将一个n*n的矩阵顺时针旋转90度。

 

 

思路:

  都是差不多的思路,交换3次也行,反转再交换也是行的。

 

技术分享
 1 class Solution {
 2 public:
 3     void rotate(vector<vector<int>>& matrix) {
 4         int i=0, n=matrix.size();
 5         while(i*2<n)
 6         {
 7             for(int j=i; j<n-i-1; j++)
 8             {
 9                 swap(matrix[n-j-1][i],matrix[n-i-1][n-j-1]);
10                 swap(matrix[n-i-1][n-j-1],matrix[j][n-i-1]);
11                 swap(matrix[j][n-i-1],matrix[i][j]);
12             }
13             i++;
14         }
15     }
16 };
AC代码

 

LeetCode Rotate Image (模拟)

原文:http://www.cnblogs.com/xcw0754/p/4937261.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!