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 生成可配置流水号

    需求背景每执行一次方法,根据公式返回最新的流水号.第一次使用时需要先插入一条数据,BizSeqValue 为流水起始号:A2014030000,Formula 为公式:A[yyyy][mm][c4], ...

  2. Rechability的简单使用

    AppDelegate.m #import "AppDelegate.h" #import "Reachability.h" @interface AppDel ...

  3. apple

    you are the apple of my eye

  4. Hadoop 中 IPC 的源码分析

    最近开始看 Hadoop 的一些源码,展开hadoop的源码包,各个组件分得比较清楚,于是开始看一下 IPC 的一些源码. IPC模块,也就是进程间通信模块,如果是在不同的机器上,那就可以理解为 RP ...

  5. Oracle 体系结构及安全管理

    1 oracle数据库服务器构成:数据库和实例2 oracle内部结构: 物理存储结构: 数据文件(xxx.dbf):存放数据 控制文件(xxx.ctl):控制数据库的完整性恢复数据或使用的日志文件 ...

  6. sql server 调优----索引缺失

    SELECT mig.index_group_handle, mid.index_handle, CONVERT (decimal (28,1), migs.avg_total_user_cost * ...

  7. MVC 用法小语法摘录

    1.类排除列

  8. Swift互用性:与 Cocoa 数据类型共舞(Swift 2.0版)-b

    本节内容包括: 字符串(Strings) 数值(Numbers) 集合类(Collection Classes) 错误(Errors) Foundation数据类型(Foundation Data T ...

  9. 在vs中连接sql的几种连接方式

     sql身份验证:Data Source=.;Initial Catalog=DBName;UID=sa;Pwd=pwd windows身份验证:Data Source=.;Initial Catal ...

  10. 嵌入式 现已发展为 IT行业的主流——高薪,且人才缺乏

    嵌入式 现已发展为 IT行业的主流——高薪,且人才缺乏 硅谷芯微技术中心,注重实践操作,以实际项目带学员,让学员真正学到东西,达到企业用人标准,有兴趣的,可以前来了解,给自己多一个选择的机会,可以多家 ...