leetcode:Rotate Image (旋转矩阵)【面试算法题】
来源:互联网 发布:窗户免费设计软件 编辑:程序博客网 时间:2024/05/18 07:19
题目:
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?
矩阵是以中心点旋转,将矩阵分成四块,遍历其中的一块数据,旋转替换其他块中对应的数据。
要替换的值的下标其实不复杂,画一个图就很容易算出。
class Solution {public: void rotate(vector<vector<int> > &matrix) { int n=matrix.size(); for(int i=0;i<n/2;++i) { for(int j=0;j<(n+1)/2;++j) { int temp=matrix[j][n-i-1]; matrix[j][n-i-1]=matrix[i][j]; matrix[i][j]=matrix[n-j-1][i]; matrix[n-j-1][i]=matrix[n-i-1][n-j-1]; matrix[n-i-1][n-j-1]=temp; } } }};// blog.csdn.net/havenoidea
- leetcode:Rotate Image (旋转矩阵)【面试算法题】
- leetcode 48. Rotate Image(矩阵旋转)
- Rotate Image 旋转矩阵 @LeetCode
- leetcode rotate-image(90°旋转矩阵)
- LeetCode Rotate Image(矩阵的旋转)
- leetcode-48 Rotate Image 旋转矩阵
- leetcode 48. Rotate Image-矩阵旋转
- leetcode 48. Rotate Image 矩阵旋转
- LeetCode-48-Rotate Image 矩阵旋转90
- 【旋转矩阵】Rotate Image
- 【LeetCode】48 Rotate Image && 【九度】题目1164:旋转矩阵
- 将矩阵顺时针旋转90度 leetCode:Rotate Image
- [leetcode 48] Rotate Image--------矩阵旋转90度
- LeetCode-----48. Rotate Image(二维矩阵旋转90度)
- LeetCode | Rotate Image(旋转图像)
- LeetCode 48. Rotate Image(旋转)
- LeetCode 48 Rotate Image(旋转图像)
- java算法之简单的二维矩阵旋转Rotate Image
- spider
- [LeetCode],Single Number II
- easyui----tooltip---提示框
- 检索结果聚类、排名
- flash 反射机制基础知识
- leetcode:Rotate Image (旋转矩阵)【面试算法题】
- 用requestAnimationFrame來做HTML5上的精準動畫
- qt开发(一): 重新上手流程
- 奇偶校验
- 黑马程序员_java 网络编程
- eCos Synthetic(仿真目标机)实践系列
- android SDK系统图片资源的路径。
- HDU 4548 -------美素数
- 关闭自动播放功能