LeetCode Rotate Image
来源:互联网 发布:php一年工作经验 编辑:程序博客网 时间:2024/06/10 16:04
题目
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?
常数空间进行旋转,
每次旋转操作需要更改旋转轮换一圈的4个点的值,
而需要操作的区域为n/2上取整,n/2下取整,一个左上角的矩形范围内的点。
代码:
class Solution {public: void rotate(vector<vector<int> > &matrix) { int len=matrix.size();//矩阵长度int len1=(len+1)/2,len2=len-len1;//需要旋转的行列数int i,j,temp;for(i=0;i<len1;i++)//依次旋转对应一圈的4个元素{for(j=0;j<len2;j++){temp=matrix[i][j];matrix[i][j]=matrix[len-1-j][i];matrix[len-1-j][i]=matrix[len-1-i][len-1-j];matrix[len-1-i][len-1-j]=matrix[j][len-1-i];matrix[j][len-1-i]=temp;}} }};
0 0
- LeetCode: Rotate Image
- [Leetcode] Rotate Image
- LeetCode : Rotate Image
- [LeetCode] Rotate Image
- leetcode 67: Rotate Image
- [leetcode] Rotate Image
- [Leetcode] Rotate Image
- [LeetCode]Rotate Image
- LeetCode-Rotate Image
- [leetcode] Rotate Image
- LeetCode - Rotate Image
- leetcode之Rotate Image
- LeetCode - Rotate Image
- Leetcode: Rotate Image
- LeetCode:Rotate Image
- Leetcode: Rotate Image
- Leetcode Rotate Image
- leetcode Rotate Image
- com学习(一)GUID 和 接口
- Experimenting with GYP
- eclipse右键很卡
- 二叉排序树的创建,以及前序、中序、后序遍历的递归实现
- word中多级编号关联多级标题并使用汉字和数字混合编号
- LeetCode Rotate Image
- sublime 空格 tab
- 工资发放系统,数据分析
- Eclipse下的Java工程用JavaProject对象获取配置信息(不用读取配置文件)
- 斯坦福大学Andrew Ng教授主讲的《机器学习》公开课观后感
- 从前有座灵剑山--有生皆愚(2)
- iOS里的MVC
- 20140629:cmd常用命令:net use、net user、format、del、mkdir。
- write once run anywhere