Rotate Image
2016-09-16 03:43
204 查看
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?
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
class Solution { public: void rotate(vector<vector<int>>& matrix) { if (matrix.empty() || matrix[0].empty()) return; int n = matrix.size(); // first swap matrix[i][j] with matrix[m - 1 - i][j] for (int i = 0; i < n / 2; i++) { for (int j = 0; j < n; j++) swap(matrix[i][j], matrix[n - 1 - i][j]); } // swap matrix[i][j] with [j][i] for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) swap(matrix[i][j], matrix[j][i]); } } };
相关文章推荐
- NYOJ题目1102Fibonacci数列
- 312. Burst Balloons
- leetcode:399. Evaluate Division
- 【工具推荐】PDF和其他格式的相关的转换
- Codeforces Round #371 (Div. 2) C. Sonya and Queries 压位、二进制来状态压缩
- Microsoft.VisualStudio.Dialogs.DialogInitializationException 问题解决
- Codeforces Round #371 (Div. 2) B. Filya and Homework STL(map or set)
- Eclipse编辑环境下使用vim插件--viplugin
- 剑指offer题目1-10
- 今天只是一个开始
- 今天只是一个开始
- Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 数学、A题第三次被系统hack了 (┬_┬)、集合交集
- 匈牙利 算法&模板
- Day17对话框
- form表单与fiddler抓包
- 【c++】指针参数是如何传递内存的
- 20160916随笔
- HDU 5446 lucas定理 + 中国剩余定理
- 调整数组顺序使奇数位于偶数前面
- oracle实例诡异down的真实原因