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. python逐行读写

    代码: fileReadObj = open("input.txt") fileWriteObj = open("output.txt", 'w') fileL ...

  2. NOI题库--图论 宗教信仰

    1526:宗教信仰 总时间限制: 5000ms 内存限制: 65536kB 描述 世界上有许多宗教,你感兴趣的是你学校里的同学信仰多少种宗教. 你的学校有n名学生(0 < n <= 500 ...

  3. 数字证书文件格式(cer和pfx)的区别

    作为文件形式存在的证书一般有这几种格式: 1.带有私钥的证书 由Public Key Cryptography Standards #12,PKCS#12标准定义,包含了公钥和私钥的二进制格式的证书形 ...

  4. C#用UPnP穿透内网

    参考了网上的一篇文章,由于时间长了,具体地址不知道了. 引入了一个DLL: Interop.NATUPNPLib.dll,实现穿透局域网,进行Socket通信. using System; using ...

  5. 最短路之Dijkstra算法

    1. 邻接矩阵 int cost[MAX_V][MAX_V]; //assume cost[u][v]>0 int d[MAX_V]; bool used[MAX_V]; void Dijkst ...

  6. 设定JS全局的公共变量

    1. 新建一个标签文件 javaScriptVariables.tag 新建一个标签文件 javaScriptVariables.tag放在 %/HelloWorldWebPro/webroot/WE ...

  7. Shell脚本获得变量值作为新变量一部分的值

    最近使用shell写一个发布脚本时,由于shell编程是边学便用的缘故,经验不足,中间遇到一个问题,一个变量的值作为一个新变量的一部分,而我要根据变量获得新变量的值,以前没有遇到过.网络搜索一番,最后 ...

  8. linux下可以禁用的一些服务

    linux下多软件/多脚本之间的配合: 包括做好 “实体”和“配置”两个方面的事情 “实体”是指实实在在的脚本文件,服务脚本: “配置”是指其他与之交互的.协同工作的软件.脚本,要进行适当的配置,告知 ...

  9. centos6.4.yum-lamp环境设置

    首先防火墙开启mysql:3306 apache 80 and 81端口: vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tc ...

  10. Entity Framework ModelFirst尝试

    前言 Model First我们称之为“模型优先”,这里的模型指的是“ADO.NET Entity Framework Data Model”,此时你的应用并没有设计相关数据库,在Visual Stu ...