给定一个 n × n 的二维矩阵表示一个图像。
将图像旋转 90 度(顺时针)。
注意:
你必须在原矩阵中旋转图像,请不要使用另一个矩阵来旋转图像。
例 1:
给出的输入矩阵 =
[
  [1,2,3],
  [4,5,6],
  [7,8,9]
],
旋转输入矩阵,使其变为 :
[
  [7,4,1],
  [8,5,2],
  [9,6,3]
]
例 2:
给出的输入矩阵 =
[
  [ 5, 1, 9,11],
  [ 2, 4, 8,10],
  [13, 3, 6, 7],
  [15,14,12,16]
],
旋转输入矩阵,使其变为 :
[
  [15,13, 2, 5],
  [14, 3, 4, 1],
  [12, 6, 8, 9],
  [16, 7,10,11]
]
详见:https://leetcode.com/problems/rotate-image/description/

Java实现:

class Solution {
public void rotate(int[][] matrix) {
int n=matrix.length;
//沿左上至右下对角线,交换对称对
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
int tmp=matrix[i][j];
matrix[i][j]=matrix[j][i];
matrix[j][i]=tmp;
}
}
//水平翻转每一行
for(int i=0;i<n;++i){
for(int j=0;j<n/2;++j){
int tmp=matrix[i][j];
matrix[i][j]=matrix[i][n-1-j];
matrix[i][n-1-j]=tmp;
}
}
}
}

参考:http://www.cnblogs.com/grandyang/p/4389572.html

https://www.cnblogs.com/lightwindy/p/8564385.html

048 Rotate Image 旋转图像的更多相关文章

  1. Leetcode48. Rotate Image旋转图像

    给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要使用另一个矩阵来旋转图像. 示例 1: 给定 m ...

  2. [LeetCode] Rotate Image 旋转图像

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

  3. Java for LeetCode 048 Rotate Image

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

  4. leetCode 48.Rotate Image (旋转图像) 解题思路和方法

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

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

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

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

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

  7. Rotate Image 旋转图像

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

  8. 【LeetCode】048. Rotate Image

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

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

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

随机推荐

  1. swoole+nginx反向代理

    nginx配置: server { listen 80; server_name www.swoole.com; root /data/wwwroot/www.swoole.com; location ...

  2. __declspec(dllimport)的小秘密(转)

    昨天和同事使用一个dll(lib+dll)的时候,发现他在引用头文件是,并没有使用__declspec(dllimport),但是程序完全运行正常,不明觉厉下,去网上翻了下资料,原来是链接器的原因,这 ...

  3. OpenCV——旋转模糊

    参考来源: 学习OpenCV:滤镜系列(5)--径向模糊:缩放&旋转 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #defi ...

  4. 【Python】数组排序

    1.numpy库:argsort() argsort函数返回的是数组值从小到大的索引值(升序排列) 一维: In [1]: import numpy as np In [2]: x = np.arra ...

  5. uC/OS-II源码分析(四)

    内核结构 1,  临界区,OS_ENTER_CRITICAL和OS_EXIT_CRITICAL 为了处理临界区代码,必须关中断,等处理完毕后,再开中断.关中断可以避免其他任务或中断进入临界区代码.uC ...

  6. 51 nod 1522 上下序列——序列dp

    题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1522 很好的思想.考虑从小到大一对一对填数,这样也能对它的大小限制 ...

  7. about future

    最近又又又重复看了 star trek 星际迷航 back to the future 1/2/3 开始想象未来是什么样子的 1. 未来的开发语言 1.1[rust] or [golang] or [ ...

  8. JMETER 定时器 之 常数吞吐量定时器

    定时器: 默认情况下,Jmeter线程在发送请求之间没有间歇.建议为线程组添加某种定时器,以便设定请求之间应该隔多长时间.如果测试人员不设定这种延迟,Jmeter可能会在短时间内产生大量访问请求,导致 ...

  9. matlab 函数 bwarea

    Matlab函数bwarea简介 函数功能:计算二值图像中对象的总面积. 调用格式: total = bwarea(BW) 估算二值图像BW中对象的总面积. 返回的total是一个标量, 它的值大致地 ...

  10. POJ-2718

    Smallest Difference Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12158   Accepted: 3 ...