48. Rotate Image

Problem's Link

----------------------------------------------------------------------------

Mean:

顺时针旋转矩阵.

analyse:

略.

Time complexity: O(N)

view code

#include <bits/stdc++.h>
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相关推荐

  1. Leetcode 48 Rotate Image

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  2. 48. Rotate Image

    48. Rotate Image 题目 You are given an n x n 2D matrix representing an image.Rotate the image by 90 de ...

  3. 【10】48. Rotate Image

    48. Rotate Image Total Accepted: 96625 Total Submissions: 259249 Difficulty: Medium Contributors: Ad ...

  4. [勇者闯LeetCode] 189. Rotate Array

    [勇者闯LeetCode] 189. Rotate Array Description Rotate an array of n elements to the right by k steps. F ...

  5. 【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 ...

  6. 48. Rotate Image ~

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  7. 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  ...

  8. Java实现 LeetCode 48 旋转图像

    48. 旋转图像 给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要使用另一个矩阵来旋转图像. 示 ...

  9. [LeetCode 题解]: Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given  ...

最新文章

  1. 2D秒变3D!视角还能随意切!华为上交提出:CIPS-3D:基于GAN的3D感知生成器
  2. Linq to sql 实现多条件的动态查询(方法一)
  3. PHP中间件ICE,ICE的安装配置,ICE常见编译和运行(异常)错误(自测Php版本安装部分,因为php版本跟ice版本不一样失败)
  4. 大数据互联网架构阶段 Spring框架导致的406错误
  5. ssm框架下文件上传
  6. 前端学习(2512):组件注册
  7. 机器数,原码,反码,补码,移码
  8. 微软宣布 SQL Server 2019 免费支持 Java
  9. webgl渲染Yuv420P图像
  10. WBE15—HttpServletRequest
  11. 使用liteide开发go遇到的问题
  12. 巧用PPT模板,远离翻车风险
  13. apk编辑器android源码,APK编辑器
  14. MYIP网站信息状态条 v1.0.1.3 (MyIP Status Bar for IE)
  15. 嘉兴 机器人仓库 菜鸟_菜鸟在嘉兴推出全新智能仓 宣布将在双11启用超级机器人仓群...
  16. OpenLayers之多源数据加载七:矢量地图
  17. STM32F103VE基于标准库下DHT11数据串口打印输出
  18. Intel 处理器模型
  19. 企业网盘到底应该怎么选?
  20. 非诚勿扰孟非经典语录

热门文章

  1. 带你通俗理解https
  2. hadoop强制删除
  3. 字符设备驱动(四)按键中断
  4. 读书笔记深入理解JVM01 关于OutOfMemoryError 堆空间的溢出
  5. 如何快速将文件中的空格更换成逗号(图文详解)
  6. CSS学习总结3:CSS定位
  7. Centos-redis安装配置
  8. uploadify 初始化的时候会请求当前页面地址
  9. 对Linux的cp命令的思考
  10. Linux 硬链接与软链接