Rotate Image

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?

Show Tags

Have you met this question in a real interview?

Yes
No

变化过程就是a(i,j)->a(j,n-i-1)->a(n-i-1,n-j-1)->a(n-j-1,i)->a(i,j),其次就是控制如何旋转,旋转的时候先旋转n*n最外层的数据,然后内层。

class Solution {
public:void smallrotate(vector<vector<int>>& matrix, int nwei, int start)//nwei表示处理的剩nwei*nwei了,总的为数是n.
{int temp;int n = matrix.size();for (int i = 0; i<nwei - 1; i++){temp = matrix[i + start][start];matrix[i + start][start] = matrix[n - 1 - start][i + start];matrix[n - 1 - start][i + start] = matrix[n - i - 1 - start][n - 1 - start];matrix[n - i - 1 - start][n - 1 - start] = matrix[start][n - i - 1 - start];matrix[start][n - i - 1 - start] = temp;}
}
void rotate(vector<vector<int>>& matrix)
{//经旋转发现,旋转90度其实就是a(i,j)->a(j,n-i-1)->a(n-i-1,n-j-1)->a(n-j-1,i)->a(i,j)int n = matrix.size();int start = 0;while (n>1){smallrotate(matrix, n, start);start++;n = n - 2;}}};

leetcode Rotate Image相关推荐

  1. LeetCode——Rotate Image(二维数组顺时针旋转90度)

    问题: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  2. LeetCode Rotate Array(数组的旋转)

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array  ...

  3. LeetCode Rotate Image(矩阵的旋转)

     You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise ...

  4. [LeetCode] Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given  ...

  5. LeetCode:Rotate Image

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  6. [LeetCode]Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given  ...

  7. leetcode Rotate Array 旋转数组

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...

  8. [LintCode/LeetCode] Rotate List

    Problem Given a list, rotate the list to the right by k places, where k is non-negative. Example Giv ...

  9. LeetCode Rotate Function(寻找规律)

    题意:给出一个数组a,长度为n 其中f(0)=0*a[0]+1*a[1]+...+(n-1)*a[n-1] f(1)=0*a[n-1]+1*a[0]+...+(n-1)*a[n-2] ... f(n- ...

最新文章

  1. 前端中会用到的设计模式之单一职责原则
  2. Unknown: Failed to get convolution algorithm. This is probably because cuDNN
  3. Android邮件发送详解
  4. android 中的invalidate 和 postInvalidate
  5. 团队作业(四):描述设计
  6. java继承circle类_java的继承
  7. 重庆大学校友会计算机,资环学院联谊会隆重举行
  8. mysql计算订单总金额_mysql统计当天消费总额
  9. java 序列化保存_保存到二进制/序列化Java
  10. 跟我一起考PMP---项目整合管理
  11. python安装notebook_Jupyter Notebook环境安装
  12. ConurrentHashMap和Hashtable的区别
  13. 日均千万级消息规模,深捷旅使用函数计算释放运维压力
  14. 联想服务器安装GHO系统,联想win7旗舰版32位gho安装教程
  15. Android:方向传感器
  16. Linux——scp的用法
  17. 利用WireShark抓包进行数据分析
  18. QQ聊天快捷键【很好用的哦】
  19. Android的StrictMode
  20. 运维之查看服务器cpu、内存、硬盘

热门文章

  1. 结构体指针变量的定义
  2. 来到fsb的第24天
  3. DirectX11 Effect特效文件
  4. linux 编程函数原型与用法
  5. SVN冲突解决方案总结
  6. DRF--序列化器类中的to_internal_value,to_representation方法,save,create,update方法
  7. QMT量化交易软件使用攻略(二)-策略编写
  8. 清除浮动的几种常用方法
  9. 0427-android-距离感应了解一下
  10. 详解randn函数及 randn('state')