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

leetcode 之Rotate Image(8)

时间:2016-05-15 21:32:30      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

        这题需要搞清楚矩阵元素的位置关系,尤其是副对角线元素,沿着副对角线元素

         

技术分享
 void rotateImage(vector<vector<int>> &matrix)
      {
          int n = matrix.size();
          //沿着副对角线翻转
          for (int i = 0; i < n;i++)
          for (int j = 0; j < n - i; j++)
          {
              swap(matrix[i][j], matrix[n - 1 - j][n - 1 - i]);
          }
          //沿着水平中线翻转
          for (int i = 0; i < n/2;i++)
          for (int j = 0; j < n; j++)
          {
              swap(matrix[i][j], matrix[n - 1 - i][j]);
          }
      }
View Code

 

leetcode 之Rotate Image(8)

标签:

原文地址:http://www.cnblogs.com/573177885qq/p/5496066.html

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