Leetcode 48 Rotate Image
来源:互联网 发布:修改php端口号 编辑:程序博客网 时间:2024/05/29 08:21
题目:
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?
思路就是先进行对角翻转,然后作左右对称
1 2 3 4 5 67 8 9
对角翻转后如下,
1 4 72 5 83 6 9
左右翻转如下
7 4 18 5 29 6 3
代码:
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 = 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[0].length / 2; ++ j) { int temp = matrix[i][j]; matrix[i][j] = matrix[i][matrix[0].length-1-j]; matrix[i][matrix[0].length-1-j] = temp; } } }}
0 0
- [leetcode 48] Rotate Image
- [LeetCode 48]Rotate Image
- leetcode || 48、Rotate Image
- leetcode-48 Rotate Image
- Rotate Image - LeetCode 48
- 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
- LeetCode 48 Rotate Image
- Leetcode 48 Rotate Image
- [Leetcode] #48 Rotate Image
- PHP pathinfo 不支持中文 手动编写解析路径字符串函数
- 三种常见字符编码简介:ASCII、Unicode和UTF-8
- spring官网资源下载方法
- 机器学习初涉--k近邻算法
- ArcGIS中字段计算器的问题
- Leetcode 48 Rotate Image
- 使用Glide原图下载方法
- 解析请求头部来自哪个浏览器---浏览器User-Agent
- JAVA集合类汇总
- linux 大杂烩
- 1617
- Ubuntu16.04 静态IP配置
- 大话设计模式,让你的代码更完美4---简单工厂模式和工厂方法模式
- linux安装tomcate