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?

解题思路:

找规律即可,JAVA实现如下:

static public void rotate(int[][] matrix) {
int[][] matrixArray=new int[matrix.length][matrix[0].length];
for(int i=0;i<matrix.length;i++)
System.arraycopy(matrix[i], 0, matrixArray[i], 0, matrix[i].length);
for(int i=0;i<matrix.length;i++)
for(int j=0;j<matrix.length;j++)
matrix[i][j]=matrixArray[matrix.length-j-1][i];
}

Java for LeetCode 048 Rotate Image的更多相关文章

  1. [Leetcode][048] Rotate Image 略详细 (Java)

    题目在这里 https://leetcode.com/problems/rotate-image/ [个人分析] 这个题目,我觉得就是考察基本功.考察细心的,算法方面没有太多东西,但是对于坐标的使用有 ...

  2. Java for LeetCode 189 Rotate Array

    Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...

  3. Java for LeetCode 061 Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...

  4. LeetCode 048 Rotate Image

    题目要求:Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 deg ...

  5. [LeetCode] 61. Rotate List 旋转链表

    Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: I ...

  6. Java for LeetCode 216 Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  7. Java for LeetCode 214 Shortest Palindrome

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  8. Java for LeetCode 212 Word Search II

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

  9. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...

随机推荐

  1. structs环境搭建

    (1)<s:fielderror />放在JSP中,如果没在web.xml中配置filter相关内容,会有The Struts dispatcher cannot be found.从而显 ...

  2. office 软件常用备忘(删除线/冻结等)

    Word: 1 大纲显示/navigation display: 视图/View --> Navigation Pane (left) 2 Track changes: 显示删除线 / 修改地方 ...

  3. opencv笔记3:trackbar简单使用

    time:2015年 10月 03日 星期六 13:54:17 CST # opencv笔记3:trackbar简单使用 当需要测试某变量的一系列取值取值会产生什么结果时,适合用trackbar.看起 ...

  4. 洛谷P1156 垃圾陷阱

    动规仍然是难关啊 题目描述 卡门――农夫约翰极其珍视的一条Holsteins奶牛――已经落了到“垃圾井”中.“垃圾井”是农夫们扔垃圾的地方,它的深度为D(2<=D<=100)英尺. 卡门想 ...

  5. rockmongo用法

    .简单查询 //xid=560870 and type=video { , "type": "video" } //查询数组中的数据 array( " ...

  6. Applying Eigenvalues to the Fibonacci Problem

    http://scottsievert.github.io/blog/2015/01/31/the-mysterious-eigenvalue/ The Fibonacci problem is a ...

  7. hdu 1241 Oil Deposits(水一发,自我的DFS)

    解题思路: 1. 遍历扫描二维数组,遇到‘@’,结果ans++; 2. 将当前 i,j 位置置为‘*’,将当前‘@’的 i,j 传人到DFS函数中,开始遍历八个方向的字符 如果碰到 '@' 则先将当前 ...

  8. hdu 2044 一只小蜜蜂

    斐波那契数列变形,在本题中不是从1-N,而是从M-N 下标   1   2   3   4   5   6   7     8     9 值     1   1   2   3   5   8   ...

  9. 锋利的jQuery-4--给事件添加命名空间

    可以把为元素绑定的多个事件用命名空间规范起来. $(function(){ $("p").bind("mouseover.plugin", function() ...

  10. dedecms最新版本修改任意管理员漏洞

    此漏洞无视gpc转义,过80sec注入防御. 补充下,不用担心后台找不到.这只是一个demo,都能修改任意数据库了,还怕拿不到SHELL? 起因是全局变量$GLOBALS可以被任意修改,随便看了下,漏 ...