【7】Rotate matrix by 90 degrees
来源:互联网 发布:jquery高级编程在线 编辑:程序博客网 时间:2024/06/05 05:10
Question:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?
package CareerCup;public class RotateMatrix {public RotateMatrix(){}public int[][] rotate(int matrix[][],int max){int[][] result = new int[max][max];for(int i=0;i<max;i++){for(int j=0;j<max;j++)result[i][j] = matrix[max-1-j][i];}return result;}public void print(int matrix[][],int max){for(int i=0;i<max;i++){for(int j=0;j<max;j++){System.out.print(matrix[i][j]+" ");}System.out.println();}}public static void main(String[] args){int[][] matrix = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};int max = 4;RotateMatrix rm = new RotateMatrix();int[][] result = rm.rotate(matrix,max);System.out.println("The orignal matrix:");rm.print(matrix, max);System.out.println("The rotated matrix:");rm.print(result, max);}}
- 【7】Rotate matrix by 90 degrees
- Ch1.6: IN-place-ly rotate a pic(NxN matrix) by 90 digree in Verilog(CPP)
- canvas.rotate(degrees)与canvas.rotate(degrees, px, py)
- rotate matrix
- matrix rotate
- Rotate Matrix
- Why are EPS files generated by gnuplot rotated 90 degrees?
- Rotate a UIImage by 90 degree angles
- Rotate Image (bi-matrix)
- [Leetcode] Rotate Matrix
- rotate matrix m*n
- 1.8 Rotate Matrix
- LeetCode - 67. Rotate Matrix
- Spiral Matrix & Spiral Matrix II & Rotate Image
- [LeetCode]Spiral Matrix I & II & Rotate Matrix
- rotate matrix from 2 vectors
- Q1.6 To rotate a image by 90 degress.
- Rotate Image By Angle 範例二
- js处理json注意了
- panabit web密码忘记后的解决方法
- 如何比较这两个字符串是否相等?
- 以deque为例详细解析容器、迭代器
- C\C++\Java字符串拼接比较
- 【7】Rotate matrix by 90 degrees
- 数据挖掘相关会议介绍
- Android程序的退出终于完美解决,兼容所有SDK
- Linux中查看系统资源占用情况的命令
- Visual Assist X添加默认包含路径+支持VS2010高亮显示CUDA代码(Windows 7)
- Unity3D组件之 Input输入控制器教程
- 【8】set matrix's elements to 0
- error: device not found解决
- activity 的四种启动模式