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?

思路:事实上就是旋转数组。没有什么难度。代码例如以下:

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("");
}
}
}

leetCode 48.Rotate Image (旋转图像) 解题思路和方法的更多相关文章

  1. [LeetCode] 48. Rotate Image 旋转图像

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  2. [leetcode]48. Rotate Image旋转图像

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  3. leetCode 72.Edit Distance (编辑距离) 解题思路和方法

    Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert  ...

  4. [array] leetcode - 48. Rotate Image - Medium

    leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...

  5. [LeetCode] 76. Minimum Window Substring 解题思路

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  6. [LeetCode] Minimum Size Subarray Sum 解题思路

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  7. [LeetCode] 45. Jump Game II 解题思路

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. [LeetCode] 234. Palindrome Linked List 解题思路

    Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time ...

  9. [LeetCode] Largest Rectangle in Histogram 解题思路

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

随机推荐

  1. SQL Server 2008中数据压缩

    SQL Server 2008中引入了数据压缩的功能,允许在表.索引和分区中执行数据压缩.这样不仅可以大大节省磁盘的占用空间,还允许将更多数据页装入内存中,从而降低磁盘IO,提升查询的性能.当然,凡事 ...

  2. oc总结

    OC10天大纲 一.类和对象 1.什么是类? 同一种对象的抽象就是类. 2.什么是对象? 世界上的任何事物都可以称为对象,每个对象都有他自己的属性和行为. 3.如何创建一个类(请把一个.h和一个.m粘 ...

  3. Swift - 10 - assert(断言)

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...

  4. IIS 配置问题解决

    无法识别的属性“targetFramework”.请注意属性名称区分大小写. 配置错误 说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件. 分析器错 ...

  5. XML约束图解

  6. Animator Override Controllers 学习及性能测试

    本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_AnimatorOverrideContorller.html  The ...

  7. Delphi-CompareStr 函数

    函数名称 CompareStr 所在单元 System.SysUtils 函数原型 function CompareStr(const S1, S2: string): Integer; 函数功能 比 ...

  8. django 内建标签和过滤器参考

    下面的标签和过滤器参考就是为那些没有 admin 站点的可用的人准备的.由于 Django 是高度可定制的,你的 admin 里的关于标签和过滤器的参考可以认为是最可信的. 内建标签参考 block ...

  9. C++中的dll

    创建动态链接库 (DLL) 项目 在菜单栏上,依次选择“文件”.“新建”.“项目”. 在“新建项目”对话框的左窗格中,依次展开“已安装”.“模板”.“Visual C++”,然后选择“Win32”. ...

  10. PHP之路——MySql查询语句

    1,select查询的基本结构 select 字段 from 表 where 过滤条件 group by 分组条件 having 过滤的第二条件 order by 排序条件 limit 限定结果条件; ...