[48]Rotate Image
来源:互联网 发布:sgd算法 矩阵分解 编辑:程序博客网 时间:2024/04/30 22:33
【题目描述】
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
【思路】如果逐步旋转的话速度太慢,考虑先沿主对角线翻转,然后再沿水平中线翻转一次。
【代码】
class Solution {public: void rotate(vector<vector<int>>& matrix) { int nz=matrix.size(); for(int i=0;i<nz;i++){ for(int j=0;j<nz-i;j++){ swap(matrix[i][j],matrix[nz-1-j][nz-1-i]); } } for(int i=0;i<nz/2;i++){ for(int j=0;j<nz;j++){ swap(matrix[i][j],matrix[nz-1-i][j]); } } } void swap(int& a,int& b){ int tmp=a; a=b; b=tmp; }};
0 0
- [leetcode 48] Rotate Image
- 48、Rotate Image
- [LeetCode 48]Rotate Image
- leetcode || 48、Rotate Image
- leetcode-48 Rotate Image
- Rotate Image - LeetCode 48
- Leetcode 48: Rotate Image
- Leetcode #48 Rotate Image
- LeetCode(48) Rotate Image
- leetcode 48: Rotate Image
- 48Rotate Image
- Leetcode#48||Rotate Image
- [48]Rotate Image
- leetcode 48:Rotate Image
- 【leetcode】【48】Rotate Image
- LeetCode_OJ【48】Rotate Image
- Leetcode 48 - Rotate Image
- LeetCode 48 - Rotate Image
- Ubuntu更新命令
- git 命令备忘
- 2015 ACM/ICPC Asia Regional Changchun Online
- Nodejs网络模块的选择
- Leetcode -- Merge Intervals
- [48]Rotate Image
- mysql 导出 sql 执行sql
- iOS的常见问题---Object-C有私有方法吗?私有变量呢?多重继承?
- 【Leetcode】之ZigZag Conversion
- cnetos 6----install ---- rpmfusion
- Han gm an Judge 模拟
- 操作系统-概念
- C++ string 用法概览
- java读取属性文件properties文件