33_leetcode_Rotate Image
来源:互联网 发布:mac跳转指定目录 编辑:程序博客网 时间:2024/06/06 08:23
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?
//1:首先考虑特殊情况;2:沿着对角线将矩阵进行对折;2:沿着最中间的列将矩阵进行再次对折。
void rotate(vector<vector<int> > &matrix) { if(matrix.size() <= 1 || matrix[0].size() == 0) return; int rows = (int)matrix.size(); int columns = (int)matrix[0].size(); //对折 for(int i = 0; i < rows; i++) { for(int j = i + 1; j < columns; j++) { swap(matrix[i][j], matrix[j][i]); } } //对折 for(int i = 0; i < rows; i++) { int start = 0; int end = columns-1; while(start < end) { swap(matrix[i][start++], matrix[i][end--]); } } return; }
0 0
- 33_leetcode_Rotate Image
- 29_leetcode_Rotate List
- Image
- Image
- Image
- Image
- image
- image
- image
- image
- Image$$
- Image
- image
- image
- Image
- image
- Image
- image
- FS269 魔晶坦克失利[第五更] _fs269魔晶坦
- 黑马程序员——foundation框架之NSNumber,NSDate,NSValue
- JSON.stringify 语法讲解
- Swift实践1 点击背景关闭键盘
- CSDN论坛问答质量提升计划
- 33_leetcode_Rotate Image
- iptables
- 34_leetcode_Jump Game
- dojo官网
- 35_leetcode_Maximum Subarray
- 36_leetcode_Count and Say
- 读《一年一度屈原祭,端午时节话公知》有感
- 在Android中动态载入自定义类
- 如何使用SSH框架开发实际项目-开发规范