Rotate Image
来源:互联网 发布:淘宝网改地址 编辑:程序博客网 时间:2024/06/09 20:46
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?
用个临时的数组,存下转换的位置再复制回去就行。
代码:
package codes;public class RotateImage {public static void main(String[] args) {int [][] matrix = {{1,2},{3,4}};new RotateImage().rotate(matrix);}public void rotate(int[][] matrix) {int size = matrix.length;int [][] res = new int[size][size];for(int i=0;i<size;i++){ for(int j = 0 ;j <size;j++){ res[j][size-1-i] = matrix[i][j]; }}for(int i=0;i<size;i++){ for(int j = 0 ;j <size;j++){ matrix[i][j] = res[i][j]; }}//for(int i=0;i<size;i++){// for(int j = 0 ;j <size;j++){// System.out.print(" "+matrix[i][j]);// }// System.out.println();//}}}
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
- php中static和const
- php中的clone对象
- php中的接口和抽象类
- php对象的序列化(串行化)用作 写入文件或者网络传输
- Unity Game Programming AI(1)人工智能导论
- Rotate Image
- php中的die()和exit()区别
- php重定向网页
- php中的const和define区别(补充)
- 初来乍到!
- Android Api Demos登顶之路(四十八)Menu
- 黑马程序员——ios基础---Objective-C:构造方法、@property、MRC
- Linux通过chmod命令改变文件权限
- 慢慢说CSS第三天