leetCode 48.Rotate Image (旋转图像) 解题思路和方法
2015-07-13 13:13
531 查看
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(""); } } }
相关文章推荐
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoa
- 程序员每天-4
- 地址映射原理和实现
- android系统标题栏的显示与否
- 思达BI软件Style Intelligence实例教程—某高校录取情况分析
- socket与http的区别
- pthread_cleanup_push()/pthread_cleanup_pop()的详解
- Gradle Project项目、Module模块导入
- 设置监听事件四种方法
- MySQL学习笔记——安装及配置环境
- 【初級篇】轻松学会华为LACP链路捆绑及二三层混绑,hybird-vlan,单臂路由
- 【初級篇】华为三层交换的配置
- cc2541 OSAL系统
- ZOJ 2366 Weird Dissimilarity (简单DP)
- leetCode 47.Permutations II (排列组合II) 解题思路和方法
- 程序猿的世界
- Ajax实现异步操作实例_针对XML格式的请求数据
- [ActionScript 3.0] 动态绘制扇形实例(拖拽绘制)
- 类中重载和重写的区别
- 字符串常量演示Demo