当前位置:网站首页>面试题 01.07. 旋转矩阵
面试题 01.07. 旋转矩阵
2022-07-27 23:29:00 【欢迎来到对抗路】
题目要求:
给你一幅由 N × N 矩阵表示的图像,其中每个像素的大小为 4 字节。请你设计一种算法,将图像旋转 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]
]
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
auto matrix1 = matrix;
int n = matrix.size();
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
matrix[i][j] = matrix1[n-j-1][i];
}
}
}
};
心得体会
stl容器中矩阵size()
i<matrix.size()//二维向量的行数的表达
matrix[i].size() //二维向量的列数表达
边栏推荐
- LeetCode 2347. 最好的扑克手牌
- Count the number of given strings in a string
- EWM收货ECC交货单校验逻辑问题
- Codeforces暑期训练周报(7.14~7.20)
- Deepening the concept of linear algebra [23] 01 - points coordinate points and vectors vectors
- Support Wu xiongang! Arm Chinese management sent an open letter: shocked and angry at the unwarranted allegations!
- 软件测试面试题:如何准备测试数据?如何防止数据污染?
- 同心向前,Google Play 十周年啦!
- BSP video tutorial issue 21: easy one key implementation of serial port DMA variable length transceiver, support bare metal and RTOS, including MDK and IAR, which is more convenient than stm32cubemx (
- 总投资近16亿元!乾照光电VCSEL、高端LED芯片项目正式开工
猜你喜欢

8000字讲透OBSA原理与应用实践

Cesium add dynamic pop-up

EWM receiving ECC delivery note verification logic problem

Unity Shader入门精要学习——基础纹理

Byte monthly salary 28K, share a wave of my automation testing experience

HarmonyOS 3正式发布:鸿蒙手机流畅安全,鸿蒙终端常用常新

Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始

ABAP CDs table function introduction and examples

LeetCode 2347. 最好的扑克手牌

Unknown database ‘xxxxx‘
随机推荐
URDF integrated gazebo
Cesium add light sweep
Huami technology "Huangshan No.2" release: AI performance is improved by 7 times, and power consumption is reduced by 50%!
Lecture 16 of project practice: using the open close principle to realize the commodity price rule engine
Codeforces summer training weekly (7.21~7.27)
比亚迪半导体完成8亿元A+轮融资:30家知名投资机构入局,估值已达102亿元!
Lua快速上手
Learn how Baidu PaddlePaddle easydl realizes automatic animal recognition in aquarium
Lua get started quickly
Flutter 通话界面UI
华为旗下哈勃投资入股VCSEL芯片厂商纵慧芯光
华米科技“黄山2号”发布:AI性能提升7倍,功耗降低50%!
Gossip: an initially perfect FS is as impractical as the first version of the program requiring no bugs
Icml2022 | online decision transformer
如何让数字零售承接起流量时代和留量时代的发展重任,或许才是关键所在
Token is used in nodejs
Three basic teaching
力挺吴雄昂!Arm中国管理层发公开信:对莫须有的指控感到震惊和愤怒!
Basic learning of cesium
BSP视频教程第21期:轻松一键实现串口DMA不定长收发,支持裸机和RTOS,含MDK和IAR两种玩法,比STM32CubeMX还方便(2022-07-24)