leetcode-java-48. Rotate Image
2016-08-29 14:31
363 查看
/* 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.在竖直中心轴对称交换 */ public class Solution { public void rotate(int[][] matrix) { int len = matrix.length; // 先对角线做转置(左下到右上) for(int i = 0;i < len;i++) { for(int j = 0;j < i;j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = temp; } } // 在竖直中心轴对称交换 for(int i = 0;i < len;i++) { for(int j = 0;j < len/2;j++) { int temp = matrix[i][j]; matrix[i][j] = matrix[i][len-1-j]; matrix[i][len-1-j] = temp; } } } }
相关文章推荐
- 修复eclipse中使用mave update project后JRE都变成1.5的问题
- 对于JAVA多线程中线程之间的通信方式的理解
- logback系列之八:自定义Pattern模板
- mac 开启多个eclipse QQ
- java创建文件和目录
- java截取字符串,截串,substring和split,分割字母和数字
- AndroidStudio 如何导入非gradle的第三方类库,也就是eclipse编的类库
- 深入浅出Java垃圾回收机制
- Spring注解
- Java poi+excel导入
- spring事务
- [个人备份]获取当月最后一天的日期
- Ansj中文分词Java开发小记
- 关于Java中指针的探讨
- java设计模式之工厂方法模式
- java 中hashmap和hashtable的区别
- OID,主键生成策略,PO VO DTO,get和load区别,脏检查,快照,java对象的三种状态
- springmvc实现Resetful风格url(maven项目)
- java基础回顾(五)——Stack、Heap
- spring如何注入Date类型的属性