这种方法首先对原数组取其转置矩阵,然后把每行的数字翻转可得到结果,如下所示(其中蓝色数字表示翻转轴):

1  2  3       1  4  7       7  4  1

4  5  6  -->   2  5  8   -->     8  5  2  

7  8  9       3  6  9          9  6  3

class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
for(int i=;i < matrix[].size();i++){
for(int j=i+;j < matrix[].size();j++){
swap(matrix[i][j],matrix[j][i]);
}
reverse(matrix[i].begin(),matrix[i].end());
}
}
};

_很好的数学思想,不是单纯的蛮力旋转

LeetCode 48的更多相关文章

  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 48. 旋转图像

    目录 # 前端与算法 leetcode 48. 旋转图像 题目描述 概要 提示 解析 解法一:转置加翻转 解法二:在单次循环中旋转 4 个矩形 算法 传入测试用例的运行结果 执行结果 GitHub仓库 ...

  3. [LeetCode] 48. 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(旋转图像)

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

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

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

  6. LeetCode——48. 旋转图像

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

  7. Java实现 LeetCode 48 旋转图像

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

  8. 每日一道 LeetCode (48):最长回文子串

    每天 3 分钟,走上算法的逆袭之路. 前文合集 每日一道 LeetCode 前文合集 代码仓库 GitHub: https://github.com/meteor1993/LeetCode Gitee ...

  9. [leetcode] 48. 旋转图像(Java)(模拟)

    48. 旋转图像 模拟题,其实挺不喜欢做模拟题的... 其实这题一层一层的转就好了,外层转完里层再转,其实就是可重叠的子问题了. 转的时候呢,一个数一个数的转,一个数带动四个数.如图所示,2这个数应该 ...

  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. tomcat的server.xml中的Context节配置

    Tomcat的默认网站目录是:C:\Tomcat 9.0\webapps\ROOT,里面的index.jsp,就是tomcat官方提供的默认页,如果按照默认配置,访问链接应当是http://local ...

  2. Spring Boot - Building RESTful Web Services

    Spring Boot Building RESTful Web Services https://www.tutorialspoint.com/spring_boot/spring_boot_bui ...

  3. jira-source--plugin

    X11 forward impact on jira plugin system initialization. 而Linux的curl使用的证书库在文件“/etc/pki/tls/certs/ca- ...

  4. ansible相关

    上图为ansible的基本架构,从上图可以了解到其由以下部分组成: 核心:ansible 核心模块(Core Modules):这些都是ansible自带的模块 扩展模块(Custom Modules ...

  5. 用MongoDB取代RabbitMQ(转)

    原文:http://blog.nosqlfan.com/html/3223.html RabbitMQ是当成应用比较广泛的队列服务系统,其配套的客户端和监控运维方案也比较成熟.BoxedIce的队列服 ...

  6. 【我的Android进阶之旅】解决Android Studio 运行gradle命令时报错: 错误: 编码GBK的不可映射字符

    1.问题描述 最近在负责公司基础业务和移动基础设施的开发工作,正在负责Lint代码静态检查工作.因此编写了自定义的Lint规则,在调试过程中,编译的时候出现了如下所示的错误: 部分输出日志如下所示: ...

  7. Tomcat安装(linux系统)

    首先解压: 进入配置文件: 统一tomcat的编码,避免乱码的问题: 保存退出. 注意: 查看打开的端口: /etc/init.d/iptables status 开启端口: iptables -A ...

  8. HDU:Gauss Fibonacci(矩阵快速幂+二分)

    http://acm.hdu.edu.cn/showproblem.php?pid=1588 Problem Description Without expecting, Angel replied ...

  9. SpringData环境搭建代码编写

    首先我们在前面的两节已经了解了SpringData是干什么用的?那我们从这节开始我们就开始编码测试SpringData. 1:首先我们从配置文件开始,我们首先需要写一个连接数据库的文件db.prope ...

  10. Java基础知识陷阱(九)

    本文发表于本人博客. 今天我来说说关于JAVA多线程知识,有错误请指出.大家都知道JAVA在服务端上处理也有很大优势,很多公司也有在服务器跑JAVA进程,这说明JAVA在处理这个多线程以及并发下也有一 ...