【LeetCode】图像
来源:互联网 发布:淘宝隐藏导航栏代码 编辑:程序博客网 时间:2024/06/08 03:58
48. Rotate Image
题目:顺时针90度旋转一个图
思路:一圈一圈转,每四个一起转换
public class Solution { public void rotate(int[][] matrix) { int i = 2; if(matrix.length%2 == 1) i = 3; for(; i <= matrix.length; i+=2){ int n = (matrix.length-i)/2; for(int j = 0; j < i-1; j++){ int temp = matrix[n][n+j]; matrix[n][n+j] = matrix[n+i-1-j][n]; matrix[n+i-1-j][n] = matrix[n+i-1][n+i-1-j]; matrix[n+i-1][n+i-1-j] = matrix[n+j][n+i-1]; matrix[n+j][n+i-1] = temp; } } }}
其实就是先进行一次以对角线为轴的对称变换,再进行一次以中心线为轴的对称变换,这样思路更加清晰
public class Solution { public void rotate(int[][] matrix) { for(int i = 0; i<matrix.length; i++){ for(int j = i; j<matrix[0].length; j++){ int temp = 0; temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } for(int i =0 ; i<matrix.length; i++){ for(int j = 0; j<matrix.length/2; j++){ int temp = 0; temp = matrix[i][j]; matrix[i][j] = matrix[i][matrix.length-1-j]; matrix[i][matrix.length-1-j] = temp; } } }}
阅读全文
0 0
- 【LeetCode】图像
- LeetCode Rotate Image旋转图像
- [LeetCode] Rotate Image 旋转图像
- LeetCode Rotate Image旋转图像
- LeetCode | Rotate Image(旋转图像)
- leetcode之图像旋转(Rotate Image)
- LeetCode 48 Rotate Image(旋转图像)
- LeetCode-Easy部分-图像平滑器
- LeetCode-661:Image Smoother (灰度图像平滑)
- LeetCode--Rotate Image(旋转图像)Python
- LeetCode OJ 之 Rotate Image (旋转图像)
- leetCode 48.Rotate Image (旋转图像) 解题思路和方法
- Leetcode #48. Rotate Image 图像旋转 解题报告
- 图像
- 图像
- 图像
- 图像
- 图像
- 解决Windows 10 下 MarkdownPad2 预览无法显示的问题
- DOM事件
- <转>MyISAM和InnoDB的索引实现
- 编码问题
- android状态栏颜色修改
- 【LeetCode】图像
- 贝叶斯公式的数学定义
- <转>堆组织表(hot)和索引组织表(iot)
- Mysql数据库存储引擎
- file递归和一些综合练习
- RocketMQ源码解析:定时消息与消息重试
- 并发 并行 同步 异步 多线程的区别
- Ubuntu如何使用锐捷客服端
- 前端性能优化之-css阻塞渲染