【leetcode】第48题 Rotate Image 题目+解析+代码
来源:互联网 发布:js有哪些内置对象 编辑:程序博客网 时间:2024/05/29 19:11
【题目】
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?
旋转矩阵discuss里一共有三个思想:
1、上下对称后,对角线对称。
2、左右对称后,对角线对称。
3、交换一个圈上的4个元素。
这三个思想都比较简单,这里只写第三个思想的代码。
【代码】
public void rotate(int[][] matrix) { int temp=0; int n=matrix.length; for(int i=0;i<n/2;i++) { for(int j=i;j<n-i-1;j++) { temp = matrix[i][j];matrix[i][j] = matrix[n - j - 1][i];matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1];matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1];matrix[j][n - i - 1] = temp; } } }
阅读全文
0 0
- 【leetcode】第48题 Rotate Image 题目+解析+代码
- LeetCode 第 48 题(Rotate Image)
- Leetcode算法题目:Rotate Image
- [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
- Codeforces Round #429 (Div 2) A
- 剑指offer——斐波那契数列
- 回文 (dp)
- es6中为什么要bind(this)
- Discuz触屏手机版显示分类信息的修改方法
- 【leetcode】第48题 Rotate Image 题目+解析+代码
- iOS_Runtime4_动态添加属性
- 基于AspectJ的注解方式进行AOP开发
- Axure chrome 扩展显示已损坏的解决方法 写在前面的话: 之前用的好好的Axure chrome 扩展如今却并不能使用,一直说扩展已损坏,额,上网下了几个.crx文件都没有用……
- pygame按键对应
- cube闪烁效果
- JavaBean规范
- 马旭东老师简介
- 字符串长度