Rotate Image
来源:互联网 发布:linux应用程序开发详解 编辑:程序博客网 时间:2024/06/05 19:26
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?
思路:先将矩阵转置,然后第一列和最后一列交换,第二列和倒数第二列交换,第三列和倒数第三列交换….直到第n/2列和倒数第n/2列交换完成即为最终的结果。
public class Solution { public void rotate(int[][] matrix) { int n=matrix.length; if(n<=0) return; int m=matrix[0].length; if(m!=n) return; for(int i=0;i<n;i++) { for(int j=0;j<i;j++) { int temp=matrix[i][j]; matrix[i][j]=matrix[j][i]; matrix[j][i]=temp; } } for(int j=0;j<=(n-1)/2;j++) { for(int i=0;i<n;i++) { int temp=matrix[i][j]; matrix[i][j]=matrix[i][n-1-j]; matrix[i][n-1-j]=temp; } } return; }}
0 0
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Rotate Image
- Android NFC开发读写NDEF数据实例
- Android 编程规范
- 程序不报错但无法运行
- 【Java】打印一个0到1之间的实数的二进制表示
- JFreeChart画图示例
- Rotate Image
- Android 混淆导包APK时报错
- 编译Android时,添加或者删除system.img中第三方apk、更改Android系统默认语言
- Android 获取系统内存
- Android项目-几种常见的应用架构
- [C++设计模式]observer 观察者模式
- adt can not found in eclipse
- Android--listview下拉刷新,上拉加载
- DNS+LAMP+NFS实现负载均衡