当前位置:网站首页>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]);
}
}
}
};边栏推荐
- Machines need tokens more than people
- Programmers architecture practice way: software architecture basic concepts and thinking
- The way of programmer architecture practice: how to design a sustainable evolution system architecture?
- opencv学习—VideoCapture 类基础知识「建议收藏」
- LeetCode——1161. 最大层内元素和
- [Bubble sort and odd-even sorting]
- 增加WebView对localStorage的支持
- 面试官:SOA 和微服务的区别?这回终于搞清楚了!
- SmobilerService 推送实现
- 【JDBC以及内部类的讲解】
猜你喜欢

Why is the new earth blurred, in-depth analysis of white balls, viewing pictures, and downloading problems

MySQL - 2059 - Authentication plugin ‘caching_sha2_password‘ cannot be loaded

怎么在外头使用容器里php命令

国内数字藏品与国外NFT主要有以下六大方面的区别

微信小程序获取用户手机号码

用于发票处理的 DocuWare,摆脱纸张和数据输入的束缚,自动处理所有收到的发票

3分钟实现内网穿透(基于ngrok实现)

Activiti产生的背景和作用

卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结

笔试题:金额拆分
随机推荐
技术总监需要会些什么?也太难了!
【MySQL功法】第4话 · 和kiko一起探索MySQL中的运算符
Machines need tokens more than people
完全背包问题的思路解析
机器比人更需要通证
Redis发布订阅和数据类型
2022年五面蚂蚁、三面拼多多、字节跳动最终拿offer入职拼多多
微信为什么使用 SQLite 保存聊天记录?
Traceback (most recent call last): File
What is the ERC20 token standard?
用于发票处理的 DocuWare,摆脱纸张和数据输入的束缚,自动处理所有收到的发票
The effects of the background and the Activiti
在线生成接口文档
国内数字藏品与国外NFT主要有以下六大方面的区别
【网络原理的概念】
FR9811S6 SOT-23-6 23V,2A同步降压DC/DC转换器
成为优秀架构师必备技能:怎样才能画出让所有人赞不绝口的系统架构图?秘诀是什么?快来打开这篇文章看看吧!...
什么是bin文件?「建议收藏」
complete knapsack problem
【一起学Rust 基础篇】Rust基础——变量和数据类型