[Leetcode] Rotate Matrix
来源:互联网 发布:在淘宝买东西可靠吗 编辑:程序博客网 时间:2024/06/05 07:40
Rotate a matrix for 90 degree in clockwise.
public void rotate(int[][] matrix) { int n = matrix[0].length; for (int i = 0; i < Math.floor(n/2) ; i++) { for (int j = i; j < n-1-i; j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[n-1-j][i]; matrix[n-1-j][i] = matrix[n-1-i][n-1-j]; matrix[n-1-i][n-1-j] = matrix[j][n-1-i]; matrix[j][n-1-i] = temp; } } }
This is how I did after stupid thinking for hours T^T.
But I think this's the most elegant solution which has the smallest time and space complex.
0 0
- [Leetcode] Rotate Matrix
- LeetCode - 67. Rotate Matrix
- [LeetCode]Spiral Matrix I & II & Rotate Matrix
- rotate matrix
- matrix rotate
- Rotate Matrix
- [LeetCode] Spiral Matrix、Rotate Image、Spiral Matrix II、Set Matrix Zeroes、Search a 2D Matrix
- Rotate Image (bi-matrix)
- rotate matrix m*n
- 1.8 Rotate Matrix
- LeetCode Rotate
- Spiral Matrix & Spiral Matrix II & Rotate Image
- rotate matrix from 2 vectors
- LeetCode: Rotate List
- LeetCode: Rotate Image
- LeetCode Rotate List
- [Leetcode] Rotate Image
- LeetCode : Rotate Image
- SJF2410烧录
- Struts2文件上传
- 项目开发界面开发部分总结
- CStatic如何影响WM_MOUSEWHEEL事件
- struts tiles
- [Leetcode] Rotate Matrix
- ZOJ 1074 To the Max (DP)
- linux yuan good
- ural 1915 Titan Ruins: Repeating Success and Failure
- 某词典软件取词问题
- OpenGL项目出现错误:error LNK2019: unresolved external symbol _gluErrorString@4
- HTTP的KeepAlive是开启还是关闭?
- 查看操作系统上文件系统块大小
- Mac OS使用技巧之三:发射无线网络信号的方法