题目要求:Rotate Image

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?

代码如下:

class Solution {
public:
void rotate(vector<vector<int> > &matrix) { const int n = matrix.size(); for(int i = 0; i < n; i++) //沿着副对角线反转
for(int j = 0; j < n - i; j++)
swap(matrix[i][j], matrix[n - 1 - j][n - 1 - i]); for(int i = 0; i < n / 2; i++)//沿着水平中线反转
for(int j = 0; j < n; j++)
swap(matrix[i][j], matrix[n - 1 - i][j]); }
};

LeetCode 048 Rotate Image的更多相关文章

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

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

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

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

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

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

  5. 【LeetCode】048. Rotate Image

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

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

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

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

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

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

  9. 【LeetCode】 Rotate List 循环链表

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

随机推荐

  1. adb、package及activity

    1.   adb adb连接手机参考:https://www.cnblogs.com/mind18/p/12592252.html,中的三.5节 1.1.  adb介绍 ADB全名Andorid De ...

  2. rpm包的卸载与安装

    1. rpm包的管理介绍:一种用于互联网下载包的打包及安装工具,它包含在某些Linux分发版中,它生成具有RPM扩展名的文件,RPM是RedHat Package Manager(RedHat软件包管 ...

  3. 深入web workers (上)

    前段时间,为了优化某个有点复杂的功能,我采用了shared workers + indexDB,构建了一个高性能的多页面共享的服务.由于是第一次真正意义上的运用workers,比以前单纯的学习有更多体 ...

  4. python实现对于告警规则的判断思路

    场景 监控一个后台服务各个url的响应时间,需要在mysql数据库的一张表中设计一个字段需要包含且不仅限于以下一种规则(1. 大于 2. 小于 3. 大于等于 4. 小于等于),表结构大概是这样的 每 ...

  5. 深入Python中的正则表达式

    正则表达式应用的场景也非常多.常见的比如:搜索引擎的搜索.爬虫结果的匹配.文本数据的提取等等都会用到,所以掌握甚至精通正则表达式是一个硬性技能,非常必要. 正则表达式 正则表达式是一个特殊的字符序列, ...

  6. Python中列表逆序

    1.list.reverse() 该方法是直接在原来的列表里面将元素进行逆序排列,不需要创建新的副本用于存储结果. 这种方式,有好处也有坏处.好处是节省内存使用,因为我们不需要重新申请空间来保存最后的 ...

  7. [C#.NET 拾遗补漏]12:死锁和活锁的发生及避免

    多线程编程时,如果涉及同时读写共享数据,就要格外小心.如果共享数据是独占资源,则要对共享数据的读写进行排它访问,最简单的方式就是加锁.锁也不能随便用,否则可能会造成死锁和活锁.本文将通过示例详细讲解死 ...

  8. WPF应用中一种比较完美的权限控制设计方式

    如题近段时间 需要在wpf应用中设计一个权限控制 , 简而言之的说 你懂的 对于IT人员来说都知道的 常见的软件功能 首先要有用户 用户,然后用户属于哪个角色 ,然后各个角色都有自己的可供操作的一堆功 ...

  9. padding的讲究

    padding有一个陷阱,你平常可能不太注意. 行内元素上设置的内边距不会影响行高计算:因此,如果一个行内元素既有内边距又有背景,从视觉上看可能会延伸到其他行,有可能还会与其他内容重叠. 对于块元素, ...

  10. shell中数字、字符串、文件比较测试

    1.逻辑运算符:与&&     或||    非!  &&:双目操作符:与运算中:如果第一个数为假,结果一定为假   ==> 短路操作符 ||:双目操作符:或运算 ...