48. Rotate Image
来源:互联网 发布:淘宝热带鱼活体 编辑:程序博客网 时间:2024/06/17 08:49
/*矩阵顺时针旋转90度,找到旋转前后对应的行列坐标关系,然后一圈一圈的往里面旋转 坐标旋转对应的关系:坐标(i,j)--->(j,n-1-i), ---> (i,j)-------- | | | | 1 2 3 | | |(n-1-j,i)-->4 5 6 <-(j,n-1-i) n:矩阵的行列长 | | | 7 8 9 | | | | ----(n-1-i,n-1-j) <- |*/#include <stdio.h>#include <iostream>#include <string>#include <sstream>#include <vector>#include <algorithm>using namespace std;class Solution {public: void rotate(vector<vector<int>>& matrix) { int n=matrix.size()-1;for(int i=0;i<=n/2;i++)//row{for(int j=i;j<n-i;j++)//column{swap(matrix[i][j],matrix[j][n-i]);swap(matrix[n-i][n-j],matrix[n-j][i]);swap(matrix[i][j],matrix[n-i][n-j]);}} }};int main(){ Solution mys;vector<std::vector<int> > matrix={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};for(int i=0;i<matrix.size();i++){ for(int j=0;j<matrix[i].size();j++) cout<<matrix[i][j]<<" ";cout<<endl;}cout<<endl;mys.rotate(matrix);for(int i=0;i<matrix.size();i++){ for(int j=0;j<matrix[i].size();j++) cout<<matrix[i][j]<<" ";cout<<endl;} return 0;}
阅读全文
0 0
- [LeetCode]48.Rotate Image
- LeetCode 48. Rotate Image
- LeetCode 48.Rotate Image
- LeetCode --- 48. Rotate Image
- [Leetcode] 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- [leetcode] 48. Rotate Image
- Leetcode 48. Rotate Image
- 48. Rotate Image LeetCode
- [LeetCode]48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- leetcode 48. Rotate Image
- Leetcode 48. Rotate Image
- LeetCode 48. Rotate Image
- OpenGL超级宝典笔记——深度纹理和阴影
- HDU 6082 度度熊与邪恶大魔王(01背包)
- css样式笔记
- PHP爬虫之解析页面的方法
- 关于国密算法 SM1,SM2,SM3,SM4 的笔记
- 48. Rotate Image
- 记一次ajax跨域访问后,session失效
- 奇异值分解的推理及意义
- 创建用户以及用户授权
- 树的可见区域的获取和滚动条监听
- 2017.8.7 用python实现简单文本编辑器
- zabbix Warning: Using a password on the command line interface can be insecure
- 盛大游戏2017校招前端工程师笔试试卷
- 封装