当前位置:网站首页>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]);
}
}
}
};边栏推荐
- Objective - C code analysis of the deep and shallow copy
- 智能日报脚本
- 用于发票处理的 DocuWare,摆脱纸张和数据输入的束缚,自动处理所有收到的发票
- 【输出一个整数的的每一位,由高到低输出。使用递归和不使用递归】
- Classical Architecture and Memory Classification of Embedded Software Components
- Skills required to be a good architect: How to draw a system architecture that everyone will love?What's the secret?Come and open this article to see it!...
- 字符串本地化和消息字典(二)
- Realize 2d characters move left and right while jumping
- 微信小程序获取手机号
- 干货!一种被称为Deformable Butterfly(DeBut)的高度结构化且稀疏的线性变换
猜你喜欢

【MySQL功法】第5话 · SQL单表查询
【一起学Rust】Rust学习前准备——注释和格式化输出

【LeetCode—第2题 两数之和 代码详解 】附有源码,可直接复制

下午见!2022京东云数据库新品发布会

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

微信为什么使用 SQLite 保存聊天记录?

html网页如何获取后台数据库的数据(html + ajax + php + mysql)

字节最爱问的智力题,你会几道?

Machine Learning (Chapter 1) - Feature Engineering

Analysis of the idea of the complete knapsack problem
随机推荐
程序员架构修炼之道:如何设计出可持续演进的系统架构?
For invoice processing DocuWare, cast off the yoke of the paper and data input, automatic processing all the invoice received
第四周学习 HybridSN,MobileNet V1,V2,V3,SENet
RTP协议分析
SmobilerService 推送实现
一个扛住 100 亿次请求的红包系统,写得太好了!!
build --repot
This article takes you to understand the principle of CDN technology
How to retrieve IDC research reports?
C#/VB.NET 从PDF中提取表格
Skills required to be a good architect: How to draw a system architecture that everyone will love?What's the secret?Come and open this article to see it!...
3分钟实现内网穿透(基于ngrok实现)
Polymorphism in detail (simple implementation to buy tickets system simulation, covering/weight definition, principle of polymorphism, virtual table)
MySQL之json数据操作
SmobilerService 推送实现
面试官:SOA 和微服务的区别?这回终于搞清楚了!
【一起学Rust】Rust包管理工具Cargo初步了解
Classical Architecture and Memory Classification of Embedded Software Components
【二分查找详解外加递归写法】附有全部代码
本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现