Leetcode-rotate-image
2016-06-26 19:59
169 查看
题目描述
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?
还是老问题,这种题目本身不难,但是加了限制条件就变难了,只能在当前空间内做旋转,这个就比较难了。
public class Solution {
public void rotate(int[][] matrix) {
int n = matrix.length;
for(int i=0; i< n/2; i++){
for(int j=0; j<Math.ceil(((double) n) / 2); j++){
int temp = matrix[i][j];
matrix[i][j] = matrix[n-1-j][i];
matrix[n-1-j][i] = matrix[n-1-i][n-1-j];
matrix[n-1-i][n-1-j] = matrix[j][n-1-i];
matrix[j][n-1-i] = temp;
}
}
}
}
需要仔细品味,找出其中门道!
相关文章推荐
- Xcode常用快捷键
- POJ3080 Blue Jeans
- LVM 逻辑卷管理器
- Java Hashtable
- ECSHOP中ajax的调用原理
- 关于Oauth认证的那些事
- 第一个spring写的helloworld,好多细节
- [代码实例][gtk+]使用builder创建UI
- 两人之间的一些参数
- 通过vscode执行python程序
- JAVA自学之每日一题(一)
- C#串口通信编程
- WinForm窗体间传值的方法
- 高级语言采用左连接统计总和
- android 蓝牙搜索功能实现
- man命令使用方法
- 机器学习的一些常用算法
- linux内核内存管理(zone_dma zone_normal zone_highmem)
- iframe 根据加载内容调整高度
- 第二章:probability distribution exercise 53-61