LeetCode Rotate Image
来源:互联网 发布:java小游戏开发 编辑:程序博客网 时间:2024/06/01 22:57
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?
思路:每次旋转的时候都一次性旋转4个数。
class Solution {public: void rotate(vector<vector<int> > &matrix) { int n = matrix.size() - 1; for (int i = 0; i < n; i++) { for (int j = i; j < n-i; j++) { int x = i, y = j; int pre = matrix[x][y]; for (int k = 0; k < 4; k++) { int next = matrix[y][n-x]; matrix[y][n-x] = pre; int tmp = x; x = y; y = n - tmp; pre = next; } } } }};
0 0
- LeetCode: Rotate Image
- [Leetcode] Rotate Image
- LeetCode : Rotate Image
- [LeetCode] Rotate Image
- leetcode 67: Rotate Image
- [leetcode] Rotate Image
- [Leetcode] Rotate Image
- [LeetCode]Rotate Image
- LeetCode-Rotate Image
- [leetcode] Rotate Image
- LeetCode - Rotate Image
- leetcode之Rotate Image
- LeetCode - Rotate Image
- Leetcode: Rotate Image
- LeetCode:Rotate Image
- Leetcode: Rotate Image
- Leetcode Rotate Image
- leetcode Rotate Image
- POJ 1804 Brainman && zzulioj 1470: Car race game(归并排序)
- io流 File类
- 设计模式之工厂模式
- Excel中反转一列数据的几种方法
- android 自定义控件实例
- LeetCode Rotate Image
- 冒泡排序
- 三层之上
- HBase二级索引与Join
- [JAVA]对象与引用、static、反射
- c++的类型转换
- STL 标准模板库 中栈stack 容器的使用
- 学习第一天
- 2.编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。在编写这个程序的时候要使用让这个程序能够处理的输入行的长度没有限制