首页 > 其他 > 详细

48. Rotate Image

时间:2016-03-02 06:54:32      阅读:105      评论:0      收藏:0      [点我收藏+]

非In-place很好做,就是纸上画一个然后转一下举个例子

 1     public void rotate(int[][] matrix) {
 2         if(matrix == null || matrix.length == 0) { 
 3             return;
 4         }
 5         int n = matrix.length;
 6         int[][] res = new int[n][n];
 7         for(int i = 0; i < n; i++) {
 8             for(int j = 0; j < n; j++) {
 9                 res[j][n - 1 - i] = matrix[i][j];
10             }
11         }
12         for(int i = 0; i < n; i++) {
13             for(int j = 0; j <n; j++) {
14                 matrix[i][j] = res[i][j];
15             }
16         }
17     }

in-place:

 

48. Rotate Image

原文:http://www.cnblogs.com/warmland/p/5233478.html

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