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

 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. BZOJ1492:[NOI2007]货币兑换——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1492 (题目描述太长了不粘贴了……) ……………………………………………………… 我 是自己做的 抄 ...

  2. HDU1561:The more, The Better——题解

    http://acm.hdu.edu.cn/showproblem.php?pid=1561 ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允 ...

  3. Warning: Received `false` for a non-boolean attribute `xxx`.

    React对boolean类型的attribute的识别方式问题,可以采用以下方法解决: xxx={value ? 1 : 0} 改成数字的写法,不用布尔值. 具体可以参考:https://githu ...

  4. apache出现You don't have permission to access / on this server. 提示

    今天在新的linux上跑原来的代码,使用的虚拟主机的模式进行操作.几个相关的网站放在一个文件里,想法是通过网站列出的目录进行相应的网站进行操作.一切设置完成后,在浏览器中运行出现在You don't ...

  5. 一维的Haar小波变换

    小波变换的基本思想是用一组小波函数或者基函数表示一个函数或者信号,例如图像信号.为了理解什么是小波变换,下面用一个具体的例子来说明小波变换的过程. 1. 求有限信号的均值和差值 [例] 假设有一幅分辨 ...

  6. Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)

    问题描述: PhoneGap+Sencha Touch开发的应用,打包后的APP或者调试期间,在启动的时候提示如下信息: Application Error - The connection to t ...

  7. HDU2121:Ice_cream’s world II (虚根+有向图最小生成树)

    Ice_cream’s world II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. maven的tomcat插件如何进行debug调试

    利用maven来部署工程时,一般采用的是tomcat插件,使项目在tomcat上面运行,那么这个debug调试是如何进行呢? 我们在调试的时候问题: 会提示找不到资源,那么如何进行修改呢,方法两个: ...

  9. Java中的String为什么是不可变的? — String源码分析

    原文地址:http://www.importnew.com/16817.html 什么是不可变对象? 众所周知, 在Java中, String类是不可变的.那么到底什么是不可变的对象呢? 可以这样认为 ...

  10. swiper 、css3制作移动端网站,折叠导航

    swiper .css3制作移动端网站,折叠导航 前几天公司要更新改版移动端的官网,由于网站本身没有多少内容,所以设计师就做成了整屏滑动的样子,起初我并没有看设计稿就一口答应了,拿到手后发现了几个问题 ...