首页 > 其他 > 详细

leetCode 48.Rotate Image (旋转图像) 解题思路和方法

时间:2015-07-13 14:02:42      阅读:356      评论:0      收藏:0      [点我收藏+]
Rotate Image

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[][] a = new int[matrix.length][matrix.length];
    	//实现深拷贝
    	for(int i = 0; i < matrix.length; i++){
    		for(int j = 0; j < matrix.length;j++){
    			a[i][j] = matrix[i][j];
    		}
    	}
    	//数据旋转
        for(int i = 0; i < a[0].length; i++){
            int k = 0;
            for(int j = a.length-1; j >=0; j--){
                matrix[i][k++] = a[j][i];
                //System.out.print(a[j][i] + " ");
            }
            //System.out.println("");
        }
    }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

leetCode 48.Rotate Image (旋转图像) 解题思路和方法

原文:http://blog.csdn.net/xygy8860/article/details/46861295

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!