Chinaunix首页 | 论坛 | 博客
  • 博客访问: 254376
  • 博文数量: 170
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1709
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-06 18:01
文章分类

全部博文(170)

文章存档

2016年(11)

2015年(130)

2014年(29)

分类: Java

2015-01-29 12:39:56

/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 RotateImage {
public void rotate(int[][] matrix) {
int row=matrix.length;
    if(row<=0)
    return;
    int column=matrix[0].length;
    if(column<=0)
    return;
    int i=0;
    int j=0;
    int temp;
    for(i=0;i     for(j=0;j<=i;++j){
    temp=matrix[i][j];
    matrix[i][j]=matrix[j][i];
    matrix[j][i]=temp; 
    }
    }
    for(i=0;i     for(j=0;j     temp=matrix[i][j];
    matrix[i][j]=matrix[i][column-j-1];
    matrix[i][column-j-1]=temp; 
    }
    }
    
}
}

阅读(766) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~