这题需要搞清楚矩阵元素的位置关系,尤其是副对角线元素,沿着副对角线元素

 void rotateImage(vector<vector<int>> &matrix)
{
int n = matrix.size();
//沿着副对角线翻转
for (int i = ; i < n;i++)
for (int j = ; j < n - i; j++)
{
swap(matrix[i][j], matrix[n - - j][n - - i]);
}
//沿着水平中线翻转
for (int i = ; i < n/;i++)
for (int j = ; j < n; j++)
{
swap(matrix[i][j], matrix[n - - i][j]);
}
}

leetcode 之Rotate Image(8)的更多相关文章

  1. [array] leetcode - 48. Rotate Image - Medium

    leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...

  2. [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 ...

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

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

  4. 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  ...

  5. LeetCode 48. Rotate Image(旋转图像)

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

  6. LeetCode 48 Rotate Image(2D图像旋转问题)

    题目链接: https://leetcode.com/problems/rotate-image/?tab=Description   Problem:给定一个n*n的二维图片,将这个二维图片按照顺时 ...

  7. 【LeetCode】 Rotate List 循环链表

    题目:rotate list 解法1: <span style="font-size:18px;">/**LeetCode Rotate List:Given a li ...

  8. [LeetCode] 189. Rotate Array 旋转数组

    Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: ...

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

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

  10. [leetcode 48] rotate image

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

随机推荐

  1. POJ3422:Kaka's Matrix Travels——题解

    http://poj.org/problem?id=3422 题目大意: 从左上角走到右下角,中途取数(数>=0),然后该点的数变为0,求走k的总价值和最大值. ———————————————— ...

  2. BZOJ4870:[SHOI2017]组合数问题——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=4870 https://www.luogu.org/problemnew/show/P3746 看网上 ...

  3. bzoj1045: [HAOI2008] 糖果传递(思维题)

    首先每个人一定分到的糖果都是所有糖果的平均数ave. 设第i个人给i-1个人Xi个糖果,则有Ai-Xi+X(i+1)=ave. 则A1-X1+X2=ave,A2-X2+X3=ave,A3-X3+X4= ...

  4. lamp 源码安装

    #!/bin/bash #description:mysql-.tar apache2.4.23 php5.6.27 function check_ok(){ ] then echo "-- ...

  5. noip模拟赛 保留道路

    [问题描述] 很久很久以前有一个国家,这个国家有N个城市,城市由1,2,3,…,N标号,城市间有M条双向道路,每条道路都有两个属性g和s,两个城市间可能有多条道路,并且可能存在将某一城市与其自身连接起 ...

  6. 查看oracle日志文件切换频率

    column avg format 999.99 column day format a6 ) "Total", , )) h0, , )) "h1", , ) ...

  7. [LeetCode] 递推思想的美妙 Best Time to Buy and Sell Stock I, II, III O(n) 解法

    题记:在求最大最小值的类似题目中,递推思想的奇妙之处,在于递推过程也就是比较求值的过程,从而做到一次遍历得到结果. LeetCode 上面的这三道题最能展现递推思想的美丽之处了. 题1 Best Ti ...

  8. Android 命名规范 (转)

    刚接触android的时候,命名都是按照拼音来,所以有的时候想看懂命名的那个控件什么是什么用的,就要读一遍甚至好几遍才知道,这样的话,在代码的审查和修改过程中就会浪费不少不必要的时间.如果就是我一个人 ...

  9. linux删除乱码

    一:前沿 好久没有记载东西了,回来之后一直忙着改东西,我走之前项目是什么样,回来后也差不多.郁闷啊,努力敲代码,但是要敲出思想来啊.先会做,然后深入思考 二:内容 (1)每次使用rz命令向服务器上传代 ...

  10. zoj 2006 Glass Beads

    Glass Beadshttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1006 Time Limit: 2 Seconds     ...