LeetCode——048
来源:互联网 发布:软件开发技术特点 编辑:程序博客网 时间:2024/06/05 07:19
/*
48. Rotate Image My Submissions QuestionEditorial Solution
Total Accepted: 66533 Total Submissions: 192145 Difficulty: Medium
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?
Subscribe to see which companies asked this question
Show Tags
Have you met this question in a real interview? Yes No
Discuss
*/
/*
解题思路:
1.将矩阵沿副对角线对折交换
2.将上一步得到的矩阵按行对折交换
*/
class Solution {public: void rotate(vector<vector<int>>& matrix) { //首先将矩阵沿副对角线进行交换 int n=matrix.size(); if(n==0)return ; for(int i=0;i<n;i++){ for(int j=0;j<n-i;j++){ swap(matrix[i][j],matrix[n-j-1][n-i-1]); } } //将矩阵行对称调换 for(int i=0;i<n/2;i++){ swap(matrix[i],matrix[n-i-1]); } }};
0 0
- LeetCode——048
- leetcode 048 —— Anagrams
- leetcode 048 —— Rotate Image
- 开始刷刷Leetcode—leetcode第二题
- LeetCode —— Combinations
- LeetCode —— Triangle
- LeetCode —— Anagrams
- [leetcode] Subsets——@
- Permutations——LeetCode
- minimum_window_substring ——leetcode
- LeetCode——Candy
- LeetCode——Triangle
- LeetCode——Combinations
- LeetCode——Permutations
- *candy——leetcode
- gas_station——leetcode
- LeetCode——Candy
- LeetCode——Triangle
- KDDCUP历年主题
- 隐马尔科夫模型
- Vmware虚拟机网络设置
- spoj16935 Straight Line Spiral Pattern (Act 3)
- 函数名 和 自己定义的普通函数指针 辨析
- LeetCode——048
- php通过curl post和get发送json数据实例 curl命令转为php源码
- Ubuntu 14.04 配置 Nginx + uWSGI 托管 virtualenv 下 Flask 应用的一点注意事项
- 阮一峰:美丽心灵的永恒阳光
- php设计模式之装饰模式
- 21-Add Two Numbers-Leetcode
- javascript中apply()和call()方法的区别
- 关于类的专题研究
- as 报错 Error:(303, 27) 错误: 找不到符号 符号: 方法 sin(float) 位置: 类 FloatMath