LeetCode - 48. Rotate Image
48. Rotate Image
Problem's Link
----------------------------------------------------------------------------
Mean:
顺时针旋转矩阵.
analyse:
略.
Time complexity: O(N)
view code
using namespace std;
class Solution
{
public:
vector<vector<int>> rotate(vector<vector<int>>& matrix)
{
int n=matrix.size();
vector<vector<int>> res;
for(int i=0;i<n;++i)
{
vector<int> nums(n);
int cnt=0;
for(int j=n-1;j>=0;--j)
nums[cnt++]=matrix[j][i];
res.push_back(nums);
}
matrix=res;
return matrix;
}
};
int main()
{
int n;
while(cin>>n)
{
vector<vector<int>> matrix(n);
for(int i=0;i<n;++i)
{
vector<int> nums(n);
for(int j=0;j<n;++j)
{
cin>>nums[j];
}
matrix[i]=nums;
}
Solution solution;
auto ans=solution.rotate(matrix);
for(auto p1:ans)
for(auto p2:p1)
cout<<p2<<" ";
cout<<endl;
}
return 0;
}
LeetCode - 48. Rotate Image相关推荐
- Leetcode 48 Rotate Image
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- 48. Rotate Image
48. Rotate Image 题目 You are given an n x n 2D matrix representing an image.Rotate the image by 90 de ...
- 【10】48. Rotate Image
48. Rotate Image Total Accepted: 96625 Total Submissions: 259249 Difficulty: Medium Contributors: Ad ...
- [勇者闯LeetCode] 189. Rotate Array
[勇者闯LeetCode] 189. Rotate Array Description Rotate an array of n elements to the right by k steps. F ...
- 【LeetCode】48. Rotate Image (2 solutions)
Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...
- 48. Rotate Image ~
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- leetcode 61 Rotate List ----- java
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- Java实现 LeetCode 48 旋转图像
48. 旋转图像 给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要使用另一个矩阵来旋转图像. 示 ...
- [LeetCode 题解]: Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
最新文章
- 2D秒变3D!视角还能随意切!华为上交提出:CIPS-3D:基于GAN的3D感知生成器
- Linq to sql 实现多条件的动态查询(方法一)
- PHP中间件ICE,ICE的安装配置,ICE常见编译和运行(异常)错误(自测Php版本安装部分,因为php版本跟ice版本不一样失败)
- 大数据互联网架构阶段 Spring框架导致的406错误
- ssm框架下文件上传
- 前端学习(2512):组件注册
- 机器数,原码,反码,补码,移码
- 微软宣布 SQL Server 2019 免费支持 Java
- webgl渲染Yuv420P图像
- WBE15—HttpServletRequest
- 使用liteide开发go遇到的问题
- 巧用PPT模板,远离翻车风险
- apk编辑器android源码,APK编辑器
- MYIP网站信息状态条 v1.0.1.3 (MyIP Status Bar for IE)
- 嘉兴 机器人仓库 菜鸟_菜鸟在嘉兴推出全新智能仓 宣布将在双11启用超级机器人仓群...
- OpenLayers之多源数据加载七:矢量地图
- STM32F103VE基于标准库下DHT11数据串口打印输出
- Intel 处理器模型
- 企业网盘到底应该怎么选?
- 非诚勿扰孟非经典语录