leetcode Rotate Image
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?
变化过程就是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相关推荐
- LeetCode——Rotate Image(二维数组顺时针旋转90度)
问题: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- 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 ...
- LeetCode Rotate Image(矩阵的旋转)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise ...
- [LeetCode] Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- LeetCode:Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- [LeetCode]Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- 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 ...
- [LintCode/LeetCode] Rotate List
Problem Given a list, rotate the list to the right by k places, where k is non-negative. Example Giv ...
- 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- ...
最新文章
- 前端中会用到的设计模式之单一职责原则
- Unknown: Failed to get convolution algorithm. This is probably because cuDNN
- Android邮件发送详解
- android 中的invalidate 和 postInvalidate
- 团队作业(四):描述设计
- java继承circle类_java的继承
- 重庆大学校友会计算机,资环学院联谊会隆重举行
- mysql计算订单总金额_mysql统计当天消费总额
- java 序列化保存_保存到二进制/序列化Java
- 跟我一起考PMP---项目整合管理
- python安装notebook_Jupyter Notebook环境安装
- ConurrentHashMap和Hashtable的区别
- 日均千万级消息规模,深捷旅使用函数计算释放运维压力
- 联想服务器安装GHO系统,联想win7旗舰版32位gho安装教程
- Android:方向传感器
- Linux——scp的用法
- 利用WireShark抓包进行数据分析
- QQ聊天快捷键【很好用的哦】
- Android的StrictMode
- 运维之查看服务器cpu、内存、硬盘