48. Rotate Image
来源:互联网 发布:org.apache.log4j pom 编辑:程序博客网 时间:2024/06/02 04:48
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
创建一个数组,直接把元素放到合适的位置。
public class Solution { public void rotate(int[][] matrix) { int n=matrix.length; int[][] res=new int[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ res[j][i]=matrix[n-1-i][j]; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ matrix[i][j]=res[i][j]; } } return; }}
先沿副对角线转置,再将数组上下翻转。
public class Solution { public void rotate(int[][] matrix) { int n=matrix.length; for(int i=0;i<n;i++){ for(int j=0;j<n-1-i;j++){ int t=matrix[i][j]; matrix[i][j]=matrix[n-1-j][n-1-i]; matrix[n-1-j][n-1-i]=t; } } for(int i=0;i<n/2;i++){ int[] t=matrix[i]; matrix[i]=matrix[n-1-i]; matrix[n-1-i]=t; } return; }}
0 0
- [LeetCode]48.Rotate Image
- LeetCode 48. Rotate Image
- LeetCode 48.Rotate Image
- LeetCode --- 48. Rotate Image
- [Leetcode] 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- [leetcode] 48. Rotate Image
- Leetcode 48. Rotate Image
- 48. Rotate Image LeetCode
- [LeetCode]48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- leetcode 48. Rotate Image
- Leetcode 48. Rotate Image
- LeetCode 48. Rotate Image
- DLL入门浅析(3)——从DLL中导出变量
- HashTable源码分析
- 设计模式-开篇
- codelab
- 欢迎使用CSDN-markdown编辑器
- 48. Rotate Image
- 把敏捷融合到瀑布式环境中
- 计算机语言
- Crazyflie微型四轴 深入解读2
- 1.简单工厂模式( Simple Factory Pattern )
- Podfile文件规范
- ios Sqlite3的简单使用 增删改查
- python_使用matplotlib画柱状图(bar),散点图(scatter)
- IOS-HTTP/Socket/TCP/IP通信协议学习总结