[LeetCode] Rotate Image 解题报告
来源:互联网 发布:淘宝网羽绒服女装 编辑:程序博客网 时间:2024/05/29 11:58
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?
Could you do this in-place?
» Solve this problem
[解题思路]
如下图,首先沿逆对角线翻转一次,然后按x轴中线翻转一次。
[Code]
1: void rotate(vector<vector<int> > &matrix) {
2: // Start typing your C/C++ solution below
3: // DO NOT write int main() function
4: int len = matrix[0].size();
5: for(int i =0; i<len-1; i++)
6: {
7: for(int j=0;j<len-i;j++)
8: {
9: swap(matrix[i][j], matrix[len-1-j][len-1-i]);
10: }
11: }
12: for(int i =0; i<len/2; i++)
13: {
14: for(int j=0;j<len;j++)
15: {
16: swap(matrix[i][j], matrix[len-i-1][j]);
17: }
18: }
19: }
20: void swap(int& a1, int&a2)
21: {
22: int temp = a1;
23: a1=a2;
24: a2=temp;
25: }
0 0
- [LeetCode] Rotate Image 解题报告
- [leetcode] 48. Rotate Image 解题报告
- Leetcode解题报告:48. Rotate Image
- [Leetcode] 48. Rotate Image 解题报告
- LeetCode 48. Rotate Image 解题报告
- Leetcode #48. Rotate Image 图像旋转 解题报告
- 【LeetCode】Rotate List 解题报告
- LeetCode-Rotate Array-解题报告
- [LeetCode] Rotate List 解题报告
- leetcode解题方案--048--Rotate Image
- [leetcode] 61. Rotate List 解题报告
- [leetcode] 189. Rotate Array 解题报告
- LeetCode 396. Rotate Function 解题报告
- [leetcode] 396. Rotate Function 解题报告
- [Leetcode] 61. Rotate List 解题报告
- [Leetcode] 189. Rotate Array 解题报告
- [leetcode]61. Rotate List@Java解题报告
- [Leetcode] 396. Rotate Function 解题报告
- [LeetCode] Restore IP Addresses 解题报告
- [LeetCode] Reverse Integer 解题报告
- [LeetCode] Reverse Linked List II 解题报告
- [LeetCode] Reverse Nodes in k-Group 解题报告
- [LeetCode] Roman To Integer 解题报告
- [LeetCode] Rotate Image 解题报告
- [LeetCode] Rotate List 解题报告
- [LeetCode] Scramble String 解题报告
- [LeetCode] Search for a Range 解题报告
- 使用flume thrift source的一点心得
- 虚拟机性能监控与故障处理工具
- [LeetCode] Search in Rotated Sorted Array 解题报告
- [LeetCode] Search in Rotated Sorted Array II 解题报告
- git管理相关命令