leetCode 48.Rotate Image (旋转图像) 解题思路和方法
2016-02-20 12:23
681 查看
Rotate Image
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?
思路:事实上就是旋转数组。没有什么难度。代码例如以下:
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?
思路:事实上就是旋转数组。没有什么难度。代码例如以下:
public class Solution { public void rotate(int[][] matrix) { int[][] a = new int[matrix.length][matrix.length]; //实现深拷贝 for(int i = 0; i < matrix.length; i++){ for(int j = 0; j < matrix.length;j++){ a[i][j] = matrix[i][j]; } } //数据旋转 for(int i = 0; i < a[0].length; i++){ int k = 0; for(int j = a.length-1; j >=0; j--){ matrix[i][k++] = a[j][i]; //System.out.print(a[j][i] + " "); } //System.out.println(""); } } }
相关文章推荐
- Could not execute auto check for display colors using command /usr/bin/xdpyinfo
- HDU 1530 Maximum Clique 最大团
- Scala中Stream的应用场景及事实上现原理
- [数据结构]七种排序算法小结
- [BZOJ4236] JOIOJI
- leetcode笔记--Add Binary
- ANDROID_MARS学习笔记_S03_002_设置可见性及扫描蓝牙设备
- leetcode笔记--Ugly Number
- leetcode--Reverse Integer
- leetcode--Plus One
- leetcode笔记--Excel Sheet Column Title
- leetcode笔记--Add Digits
- 服务器端学习(一) 如何把自己的电脑作为网站服务器
- linux防火墙开对指定ip段开放端口
- 浅谈Java中的序列化
- 数据结构(6)--栈的应用之中缀表达式求值
- 数据库_1: MySQL:基础
- jQuery
- animationWithKeyPath
- 进程与线程