LintCode:旋转图像
来源:互联网 发布:mac黑屏音乐不播放 编辑:程序博客网 时间:2024/05/24 05:53
给定一个N×N的二维矩阵表示图像,90度顺时针旋转图像。
Yes
样例
给出一个矩形[[1,2],[3,4]],90度顺时针旋转后,返回[[3,1],[4,2]]
挑战
标签 Expand 能否在原地完成?
相关题目 Expand
解题思路:
旋转90°其实可以理解为数组先上下对折,然后再进行对角线对折就ok了。
http://www.2cto.com/kf/201410/341031.html
http://www.cnblogs.com/easonliu/p/3649422.html
public class Solution { /** * @param matrix: A list of lists of integers * @return: Void */ public void rotate(int[][] matrix) { // write your code here if(matrix==null||0==matrix.length) return; int m = matrix.length; /**上下进行翻转**/ for(int i=0;i<m/2;i++){ for(int j=0;j<m;j++){ int tmp = matrix[i][j]; matrix[i][j] = matrix[m-1-i][j]; matrix[m-1-i][j] = tmp; } } /**对角线进行翻转**/ for(int i=0;i<m;i++){ for(int j=0;j<i;j++){ int tmp = matrix[i][j]; matrix[i][j] = matrix[j][i]; matrix[j][i] = tmp; } } }}
0 0
- LintCode-旋转图像
- lintcode-旋转图像-161
- LintCode:旋转图像
- LintCode:旋转图像
- LintCode 161-旋转图像
- 旋转图像-LintCode
- [LintCode] 旋转图像 Rotate Image
- LintCode-旋转链表
- LintCode-旋转链表
- LintCode:旋转链表
- LintCode:旋转字符串
- lintcode ----旋转字符串
- Lintcode 恢复旋转数组
- LintCode 8 旋转字符串
- LintCode : 旋转链表
- Lintcode 旋转字符串
- LintCode 旋转字符串
- lintcode--旋转字符串
- iOS开发多线程-线程间的通信
- Java FP: Java中函数式编程的Map和Fold(Reduce)
- select * from table1 where id =‘1’ for update
- tomcat对线程池的扩展
- http://macrochen.iteye.com/blog/1414568
- LintCode:旋转图像
- finereport的服务器负载均衡部署--tomcat
- !
- LintCode:旋转链表
- IBM Cloudant分布式NoSQL数据库介绍
- 关于addSpriteFramesWithFile读取失败
- maven 安装纪录
- mysql下如何执行sql脚本
- JavaFX入门(三):使用Eclipse开发JavaFX程序