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. Codeforces 46D Parking Lot

    传送门 D. Parking Lot time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. 深入浅出MySQL双向复制技术

    设置MySQL数据同步(单向&双向)由于公司的业务需求,需要网通和电信的数据同步,就做了个MySQL的双向同步,记下过程,以后用得到再翻出来,也贴出来供大家参考. 一.准备服务器 由于MySQ ...

  3. 浏览器的中的 XMLHttpRequest 对象的使用

    使用XMLHttpRequest浏览器对象(IE5.IE6中是ActiveXObject对象)可以实现异步请求,Ajax就是以此为基础进行的封装. 1.同步与异步: <script type=& ...

  4. VS2012变化的快捷键:

    VS2012变化的快捷键: 注释::VS2010是(Ctrl+E,C),VS2012是(Ctrl+K, Ctrl+C),实际操作,按住Ctrl键不放,先按K键,再按C键.相当于Ctrl+K加 Ctrl ...

  5. ucenter实现原理

    其实Ucenter实现同步登陆的原理就是cookie,一个应用登陆成功之后,向Ucenter传递数据(post方式),让Ucenter通知其他的应用也设置 cookie(get方式),这样用户在访问其 ...

  6. Javascript输出表格

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. 调用MySql 分页存储过程带有输入输出参数

    Create PROCEDURE getuser ( IN pageIndex INT, IN pageSize INT, OUT count INT ) BEGIN )*pageSize; sele ...

  8. Caused by: java.lang.NoSuchFieldError: TRACE

    Caused by: java.lang.NoSuchFieldError: TRACE at org.slf4j.impl.Log4jLoggerAdapter.trace(Log4jLoggerA ...

  9. php url地址重写

    地址重写: urlRewrite: 就是:  1. 将php的地址index.php不写只写Action模块和function方法, 或者 2. php地址转变成html地址, 就是一种假的html, ...

  10. mysql更新一个表里的字段等于另一个表某字段的值

    update a left join c on a.id = c.id set a.body = c.c1 where a.id=c.id; update zcat as z left join zc ...