leetcode 48. Rotate Image
来源:互联网 发布:手机淘宝与支付宝解绑 编辑:程序博客网 时间:2024/06/05 01:04
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up:
Could you do this in-place?
给你一个n*n的二维矩阵,顺时针旋转90°,不申请额外的空间.
先关于主对角线对称,再左右对称.
public class A048RotateImage {public void rotate(int[][] matrix) { int n = matrix.length; // 转置(关于主对角线对称) for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } // 左右对称 for(int i = 0; i < n; i++) { for(int j = 0; j < n / 2; j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[i][n - j - 1]; matrix[i][n - j - 1] = temp; } } }}
1 0
- [LeetCode]48.Rotate Image
- LeetCode 48. Rotate Image
- LeetCode 48.Rotate Image
- LeetCode --- 48. Rotate Image
- [Leetcode] 48. Rotate Image
- [leetcode] 48. Rotate Image
- Leetcode 48. Rotate Image
- 48. Rotate Image LeetCode
- [LeetCode]48. Rotate Image
- leetcode 48. Rotate Image
- Leetcode 48. Rotate Image
- LeetCode 48. Rotate Image
- LeetCode *** 48. Rotate Image
- [LeetCode]48. Rotate Image
- LeetCode 48. Rotate Image
- LeetCode-48.Rotate Image
- [LeetCode] 48. Rotate Image
- LeetCode 48. Rotate Image
- ruby中星号(*)的作用
- ToggleButton
- Linux:Centos7升级内核
- Android Xfermode 实战 实现圆形、圆角图片
- Windows 64位驱动 关闭内存保护
- leetcode 48. Rotate Image
- netstat 中 Recv-Q和Send-Q状态
- poj1182食物链
- UDP网络编程
- 使用Google ZXing实现二维码的扫描和生成相关功能体系
- Android应用获取设备序列号
- oracle数据库一些基本sql操作
- Cell上的subView添加手势 与 cell点击手势冲突
- IOS使用Reachability实时检测网络连接状况