CCI 1.6 旋转矩阵
来源:互联网 发布:2016淘宝搜索规则 编辑:程序博客网 时间:2024/05/17 02:46
给定一幅由N*N矩阵表示的图像,其中每个像素的大小为4字节,编写一个方法,将图像旋转90度。不占用额外内存空间能否做到?
package test;public class RotateMatrix {public static void rotateMatrix(int[][] matrix){if(matrix==null || matrix.length==0 || matrix[0]==null || matrix[0].length==0)return;if(matrix.length != matrix[0].length)return;int n = matrix.length;for(int layer=0; layer < n/2; layer++){int first = layer;int last = n-layer-1;for(int i=first; i<last; i++){int offset = i-first;int temp = matrix[i][first];matrix[i][first] = matrix[last][i];matrix[last][i] = matrix[last-offset][last];matrix[last-offset][last] = matrix[first][last-offset];matrix[first][last-offset] = temp;}}}public static void main(String[] args) {// TODO Auto-generated method stubint[][] case1 = null;int[][] case2 = { {1,2,3}, {4,5,6}, {7,8,9} };int[][] testCase = case2;rotateMatrix(testCase);for(int i=0; i<testCase.length; i++){for(int j=0; j<testCase[0].length; j++){System.out.print(testCase[i][j]);System.out.print(" ");}System.out.println();}}}
0 0
- CCI 1.6 旋转矩阵
- CCI 1.7 矩阵行列清零
- CCI 9.7 矩阵填充颜色
- 1.6 矩阵旋转
- cci-Q1.6 矩形90度旋转
- CI 1.6 矩阵旋转--图像旋转
- 旋转矩阵
- 矩阵旋转
- 旋转矩阵
- 旋转矩阵
- 旋转矩阵
- 旋转矩阵
- 矩阵旋转
- 旋转矩阵
- 旋转矩阵
- 矩阵旋转
- 矩阵 旋转
- 矩阵旋转
- servlet 的实现方法
- [信号处理技术]关于EMD的产生
- The Slow Query Log
- Linux实现的IEEE 802.1Q VLAN
- svn命令——(转载)
- CCI 1.6 旋转矩阵
- Hduoj1003!【DP】
- win32平台关于“pure virtual function call”的解释
- myeclipse如何恢复删除的文件
- Idea 实现热部署
- c# 自动转html 到stringbuilder 输出内容。
- 错误处理
- poj 1273
- mysqldumpslow — Summarize Slow Query Log Files