*LeetCode-Rotate Image
来源:互联网 发布:淘宝修改密码网址 编辑:程序博客网 时间:2024/05/29 12:56
cc书上的方法就是每一层分成四个 旋转 index非常难想
public class Solution { public void rotate(int[][] matrix) { int n = matrix.length; for ( int i = 0; i < n / 2; i ++ ){ int [] temp = new int [n-2*i-1]; for ( int j = 0; j < n-2*i -1; j ++ ){ temp[ j ] = matrix[i][j+i]; matrix[i][j+i] = matrix[n-i-j-1][i]; matrix[n-i-j-1][i] = matrix[n-i-1][n-i-j-1]; matrix[n-i-1][n-i-j-1] = matrix[i+j][n-i-1]; matrix[i+j][n-i-1] = temp[j]; } } return; }}
第二种方法很巧妙 就是先上下reverse 然后对角线swap
public class Solution { public void rotate(int[][] matrix) { int n = matrix.length; for(int i = 0; i < n / 2; i++){ int [] temp = matrix[i]; matrix[i] = matrix[matrix.length - i - 1]; matrix[matrix.length - i - 1] = temp; } for ( int i = 0; i < n; i ++ ){ for ( int j = 0; j < i; j ++ ){ int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } return; }}
0 0
- LeetCode: Rotate Image
- [Leetcode] Rotate Image
- LeetCode : Rotate Image
- [LeetCode] Rotate Image
- leetcode 67: Rotate Image
- [leetcode] Rotate Image
- [Leetcode] Rotate Image
- [LeetCode]Rotate Image
- LeetCode-Rotate Image
- [leetcode] Rotate Image
- LeetCode - Rotate Image
- leetcode之Rotate Image
- LeetCode - Rotate Image
- Leetcode: Rotate Image
- LeetCode:Rotate Image
- Leetcode: Rotate Image
- Leetcode Rotate Image
- leetcode Rotate Image
- zoj1163The Staircases
- 查看服务器日志相关
- 图
- Cannot create JDBC driver of class '' for connect URL 'null’
- Http协议讲义及相应过程
- *LeetCode-Rotate Image
- #1057 : Performance Log 线程日志(栈模拟)
- java正则表达式
- servlet内置对象
- JSP编码以及乱码解决总结
- 作用域
- CentOS 6下Nvidia显卡驱动程序的安装整理总结
- poj1106Transmitters【求旋转半圆能覆盖的最多点数】
- EmguCV录制视频