当前位置:网站首页>Leetcode 48. 旋转图像(可以,已解决)
Leetcode 48. 旋转图像(可以,已解决)
2022-06-28 11:33: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
Code:
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
vector<int>res;
int size=matrix.size();
for(int i=0;i<matrix.size();i++)
{
vector<int>sub=matrix[i];
for(int j=0;j<sub.size();j++)
{
res.push_back(sub[j]);
}
}
vector<int>newvec;
for(int i=res.size()-size,row=0;i<res.size();i++,row++)
{
int j=i;
int col=0;
do
{
// cout<<res[j]<<" ";
newvec.push_back(res[j]);
matrix[row][col++]=res[j];
j-=size;
if(j>=0&&j<size)
{
// cout<<res[j]<<" ";
newvec.push_back(res[j]);
matrix[row][col++]=res[j];
break;
}
if(j<0)
{
break;
}
}while(1);
cout<<endl;
}
}
};
边栏推荐
- Mutual conversion between mytipartfile and file
- day23 js笔记 2021.09.14
- Daily practice of C language - day 4: find the sum of all even numbers within 100
- Day24 JS notes 2021.09.15
- Which programming language will attract excellent talents?
- day31 js笔记 DOM下 2021.09.26
- js中的class类模式及语法 2021.11.10
- 多维度监控:智能监控的数据基础
- Contract quantitative trading system development | contract quantitative app development (ready-made cases)
- js中的数组方法 2021.09.18
猜你喜欢

智联招聘基于 Nebula Graph 的推荐实践分享

js中的class类模式及语法 2021.11.10

Class pattern and syntax in JS 2021.11.10

《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!

2022中国信通院首届业务与应用安全发展论坛成功召开!

Why do many people want to change careers as programmers, while some programmers want to change careers as others?

Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community

JS foundation 8

Remote login sshd service

网页提示此站点不安全解决方案
随机推荐
Graphics view framework for QT learning (to realize startup animation)
Still using simpledateformat for time formatting? Be careful that the project collapses!
零基础C语言(一)
Is it feasible to be a programmer at the age of 26?
Day39 prototype chain and page Fireworks Effect 2021.10.13
一套十万级TPS的IM综合消息系统的架构实践与思考
分析list中有无重复数据且重复了几次
Day29 JS notes 2021.09.23
Daily practice of C language - day 4: find the sum of all even numbers within 100
4. maximum continuity factor
无法重新声明块范围变量
Come on, yuanuniverse. Sure enough, the heat won't pass for a while
Day32 JS note event (Part 1) September 27, 2021
使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
recent developments
董宇辉,新东方以及凤凰卫视
MapReduce项目案例1
Is it safe to buy stocks and open an account on the account QR code of the CICC securities manager? Ask the great God for help
Jetpack Compose Desktop 桌面版本的打包和发布应用
Which programming language will attract excellent talents?