当前位置:网站首页>Leetcode 48. Rotate image (yes, resolved)
Leetcode 48. Rotate image (yes, resolved)
2022-06-28 14:58:00 【I'm not xiaohaiwa~~~~】

Given a n × n Two dimensional matrix of matrix Represents an image . Please rotate the image clockwise 90 degree .
You must be there. In situ Rotated image , This means that you need to modify the input two-dimensional matrix directly . Please do not Use another matrix to rotate the image .
Example 1:

Input :matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output :[[7,4,1],[8,5,2],[9,6,3]]
Example 2:
Input :matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Output :[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
Tips :
- 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;
}
}
};
边栏推荐
- 华为能成“口红一哥”,或者“带货女王”吗?
- 叮!Techo Day 腾讯技术开放日如约而至!
- Jackie Chan and fast brand, who is the Savior of Kwai?
- Configuration file encryption (simple use of jasypt)
- [C language] how to implement plural types
- Construction and management practice of ByteDance buried point data flow
- 买卖股票的最佳时机
- 股票开户优惠链接,我如何才能得到?手机开户是安全么?
- Talking from the little nematode -- tracing the evolution of nervous system and starting life simulation
- 【mysql学习笔记24】索引设计原则
猜你喜欢
![[Zhongyi Xinsheng] 5 SPI interface test TF Card](/img/d9/56ded362b3055f4f0efc3ce0eec5d5.jpg)
[Zhongyi Xinsheng] 5 SPI interface test TF Card

Talking from the little nematode -- tracing the evolution of nervous system and starting life simulation

张同学还没学会当主播

美国乔布斯,殁了;中国乔布斯,卖了

Flutter series: offstage in flutter

抽奖动画 - 鲤鱼跳龙门

With 120billion yuan, she will ring the bell for IPO again

【黑马早报】腾讯回应大批用户QQ号被盗;薇娅丈夫公司被罚19万;中国恒大被申请清盘;关晓彤奶茶店回应被加盟商起诉...

dolphinscheduler2. Installation of X (valid for personal test)

坐拥1200亿,她又要IPO敲钟了
随机推荐
量子前沿英雄谱|“光量子探险家”McMahon:将任何物理系统变成神经网络
请问一下,是不是insert all这种oracle的批量新增没拦截?
spacy教程(持续更新ing...)
运行近20年,基于Win 98的火星探测器软件迎来首次升级
Seata数据库中出现以下问题要怎么解决呀?
Which securities company is the largest and safest? How to open an account is the safest
Performance comparison of deep learning models on cat and dog image data sets
How to solve the following problems in the Seata database?
法兰克福地区目前支持sql了吗?
10 key points to effectively improve performance interview
Flutter series: offstage in flutter
优巨新材冲刺深交所:拟募资6.5亿 年营收3.33亿
Summary of technical difficulties of wearable neural signal and behavior data detection and recording system for birds in flight
324. swinging sort II: not a simple construction problem
力扣今日题-522. 最长特殊序列
币圈大地震:去年赚100万,今年亏500万
JS judge whether the string is empty or not
How does Seata server 1.5.0 support mysql8.0?
The boss told me three times: low key, low key, low key
Differences between ram ROM flash