首页 > 其他 > 详细

[Leetcode] Rotate Image

时间:2014-11-14 17:15:18      阅读:235      评论:0      收藏:0      [点我收藏+]

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?

 

Solution:

public class Solution {
    public void rotate(int[][] matrix) {
        int N=matrix.length-1;
        if(N<1)
            return;
        for(int i=0;i<=N/2;++i){
            for(int j=i;j<N-i;++j){
                int temp=matrix[N-j][i];
                matrix[N-j][i]=    matrix[N-i][N-j];
                matrix[N-i][N-j]=matrix[j][N-i];
                matrix[j][N-i]=matrix[i][j];
                matrix[i][j]=temp;
            }
        }
    }
}

 

[Leetcode] Rotate Image

原文:http://www.cnblogs.com/Phoebe815/p/4097669.html

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