当前位置:网站首页>LeetCode-48. 旋转图像
LeetCode-48. 旋转图像
2022-08-03 11:29:00 【边界流浪者】
给定一个 n × n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。
你必须在 原地 旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像。
示例 1:
输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
输出:[[7,4,1],[8,5,2],[9,6,3]]
示例 2:
输入:matrix = [[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]]
提示:
n == matrix.length == matrix[i].length
1 <= n <= 20
-1000 <= matrix[i][j] <= 1000
先上下翻转,再按照对角线翻转
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int n = matrix.size();
for(int i = 0; i < n / 2; i++)
matrix[i].swap(matrix[n - 1 - i]);
for(int i = 0; i < n; i++) {
for(int j = i; j < n; j++) {
swap(matrix[i][j], matrix[j][i]);
}
}
}
};
边栏推荐
- 87.(cesium之家)cesium热力图(贴地形)
- Analysis of the idea of the complete knapsack problem
- 【Mysql】清理binlog日志的方法
- 【一起学Rust】Rust包管理工具Cargo初步了解
- 浅谈SVN备份
- Machine Learning (Chapter 1) - Feature Engineering
- [LeetCode—Question 2 Sum of Two Numbers Detailed Code Explanation ] The source code is attached, which can be copied directly
- MySQL database combat (1)
- RICON:NER SOTA 又来!
- Traceback (most recent call last): File
猜你喜欢
图新地球为什么很模糊,白球、看图、下载问题深度剖析
【一起学Rust 基础篇】Rust基础——变量和数据类型
国内数字藏品与国外NFT主要有以下六大方面的区别
嵌入式软件组件经典架构与存储器分类
fast planner中拓扑路径搜索
最牛逼的集群监控系统,它始终位列第一!
缓存--伪共享问题
LeetCode 899 Ordered queue [lexicographical order] HERODING's LeetCode road
Classical Architecture and Memory Classification of Embedded Software Components
Android 技术面试准备(含面试题及答案)
随机推荐
Traceback (most recent call last): File
Why is the new earth blurred, in-depth analysis of white balls, viewing pictures, and downloading problems
字符串本地化和消息字典(二)
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
What is the relationship between The Matrix and 6G?
Activiti产生的背景和作用
Babbitt | Metaverse daily must-read: Players leave, platforms are shut down, and the digital collection market is gradually cooling down. Where is the future of the industry?...
fast planner中拓扑路径搜索
RTP协议分析
试题G:单词分析 ← 第十一届蓝桥杯大赛第二场省赛赛题
VRRP协议的作用及VRRP+OSPF配置方法
redis基础知识总结——数据类型(字符串,列表,集合,哈希,集合)
LeetCode——622.设计循环队列
【TypeScript】为什么要选择 TypeScript?
RICON:NER SOTA 又来!
LP流动性挖矿DAPP系统开发丨流动性挖矿功能原理及说明
[论文阅读] (23)恶意代码作者溯源(去匿名化)经典论文阅读:二进制和源代码对比
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
深度学习:文本CNN-textcnn
本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现