首页 > 其他 > 详细

Rotate Image

时间:2015-04-11 16:17:44      阅读:101      评论:0      收藏:0      [点我收藏+]

给定一个n*n的二维向量,顺时针旋转90度

  1. class Solution {
  2. public:
  3. void rotate(vector<vector<int> > &matrix) {
  4. int length = matrix.size();
  5. for (int i = 0; i < length/2; i++)
  6. {
  7. for (int j = i; j < length - i - 1; j++)
  8. {
  9. int tmp = matrix[i][j];
  10. matrix[i][j] = matrix[length - j - 1][i];
  11. matrix[length - j - 1][i] = matrix[length - i - 1][length - j - 1];
  12. matrix[length - i - 1][length - j - 1] = matrix[j][length - i - 1];
  13. matrix[j][length - i - 1] = tmp;
  14. }
  15. }
  16. }
  17. };




Rotate Image

原文:http://www.cnblogs.com/flyjameschen/p/5d92c59daba1cc6b261b48be661bd118.html

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