当前位置:网站首页>面试题 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() //二维向量的列数表达
边栏推荐
- JUC concurrent programming learning
- Monitor mouse sideslip (adapt to mobile terminal)
- At the meeting on June 19, SMIC may set the fastest listing record in China!
- Tool function: pay the non empty field value in one workspace to the same field in another workspace
- Software process that testers need to know
- Flutter--密码登录注册界面
- Cesium add light sweep
- spreadsheet 导出 excel表格
- 开发 Flutter 录音功能的插件
- How to solve the pain points of 12000 small and medium-sized customers' component procurement? Say goodbye to overtime!
猜你喜欢
随机推荐
Centralized management of clusters
Fabric2.4.4 version building process (complete process)
The cooperation between starfish OS and metabell is just the beginning
Three instance
Advanced MySQL -- stored procedures and custom functions
3年经验想拿20K,居然面了半个月都没拿到?
BYD semiconductor completed the a+ round financing of 800million yuan: 30 well-known investment institutions entered the market, with a valuation of 10.2 billion yuan!
Xinyi information technology, a domestic NB IOT chip manufacturer, received 200million yuan of a+ round financing
3000 words and 11 pictures hard core popular science: what is edge computing? What are the connections and differences with cloud computing?
软件测试面试题:如何发现数据库的相关问题?
BSP视频教程第21期:轻松一键实现串口DMA不定长收发,支持裸机和RTOS,含MDK和IAR两种玩法,比STM32CubeMX还方便(2022-07-24)
Huawei's Hubble investment shares in VCSEL chip manufacturer Zonghui Xinguang
mysql-JPA对数据库中JSON类型数据的支持
Huawei responded to the US blockade of the supply chain: they still have to pay for 5g patents
S-RPN: Sampling-balanced region proposal network for small crop pest detection
HarmonyOS 3正式发布:鸿蒙手机流畅安全,鸿蒙终端常用常新
8000 word explanation of OBSA principle and application practice
ABAP CDs table function introduction and examples
Huami technology "Huangshan No.2" release: AI performance is improved by 7 times, and power consumption is reduced by 50%!
Rviz 使用Arbotix控制机器人运动









