1、题目描述

2、分析

使用了一个队列。

3、代码

 1 vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
 2
 3         if( nums.size() * nums[0].size()  !=  r * c )
 4             return nums;
 5         vector<vector<int>> ans;
 6         queue<int> q;
 7         for( size_t i = 0; i < nums.size() ;i++ )
 8             for( size_t j =0; j < nums[0].size() ;j++)
 9                 q.push( nums[i][j] );
10
11         vector<int> col;
12         while( !q.empty()  )
13         {
14             col.push_back( q.front() );
15             q.pop();
16             if( col.size() == c )
17             {
18                 ans.push_back( col );
19                 col.clear();
20             }
21         }
22
23         return ans;
24
25     }

转载于:https://www.cnblogs.com/wangxiaoyong/p/8929536.html

leetCode题解之Reshape the Matrix相关推荐

  1. leetcode讲解--566. Reshape the Matrix

    题目 In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a ne ...

  2. python矩阵reshape_[LeetCode Python3]566. Reshape the Matrix(重塑矩阵)

    在MATLAB中,有一个非常有用的函数 reshape,它可以将一个矩阵重塑为另一个大小不同的新矩阵,但保留其原始数据. 给出一个由二维数组表示的矩阵,以及两个正整数r和c,分别表示想要的重构的矩阵的 ...

  3. Leetcode PHP题解--D53 566. Reshape the Matrix

    2019独角兽企业重金招聘Python工程师标准>>> D53 566. Reshape the Matrix 题目链接 566. Reshape the Matrix 题目分析 给 ...

  4. LeetCode 566 Reshape the Matrix 解题报告

    题目要求 In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a ...

  5. LeetCode 566. Reshape the Matrix

    题目: In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a n ...

  6. C#LeetCode刷题之#566-重塑矩阵( Reshape the Matrix)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3720 访问. 在MATLAB中,有一个非常有用的函数 resha ...

  7. 900 多道 LeetCode 题解,这个 GitHub 项目值得 Star!

    转自 | 码农有道 大家好,我是小 G. 周末风和日丽,适合刷 LeetCode 今天给你们推荐个 GitHub 项目,里面收集了 900 多道 LeetCode 题解,并包含中英文两个版本,适合大多 ...

  8. PHP版Leetcode题解开始随缘更新

    2019独角兽企业重金招聘Python工程师标准>>> PHP版Leetcode题解 我叫skys215,是一名bug工程师. 我接触编程的时间比较早,但是因为我数学不好加上比较懒, ...

  9. [LeetCode 题解]: Binary Tree Preorder Traversal

    前言 [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a binary ...

最新文章

  1. poj 2987 Firing【最大权闭合子图+玄学计数 || BFS】
  2. Python-基于flask的接口框架
  3. Android非UI线程更新UI的几种方法
  4. 【若依(ruoyi)】验证码
  5. LeetCode 2119. 反转两次的数字
  6. C/C++ OpenCV直方图均衡化
  7. JSON-lib框架,转换JSON、XML不再困难
  8. Html5的测试总结
  9. 解决win10系统俄罗斯精简版用不了打印机问题
  10. java实现代码在线编译器-从零开发(一)简单本地编译+运行测试
  11. TensorFlow实现图像风格迁移
  12. 海王夺回王位科学深意:杂种是怎么一步步主宰地球的
  13. 波长与颜色的对应关系之python实现
  14. 在NS2(2.35版本)中添加 Ping协议
  15. 华为 eNsp ipSec vpn实验配置(1)
  16. 点到超平面距离的原理推导
  17. 全国计算机三级考试网络技术--应用题总结
  18. 遇到《顺丰速运》app奔溃了,怎么回事呢?
  19. 斯人若彩虹,遇上方知有——dbGet(一)
  20. 如何提高专业英文阅读能力

热门文章

  1. creator 静态属性_CocosCreator cc.class声明类
  2. 解决神经网络过拟合问题—Dropout方法、python实现
  3. python 通过pip安装库 pycharm里面使用第三方库
  4. c 通过jni调用java_使用c通过jni调用java
  5. mysql undrop_MySQL 如何对InnoDB使用Undrop来恢复InnoDB数据
  6. 贪心法田忌赛马问题Java代码,hdoj 1052 Tian Ji - The Horse Racing【田忌赛马】 【贪心】...
  7. flash 火狐总是崩溃_win10系统火狐flash插件总是崩溃的解决方法
  8. linux闹钟软件下载,电量充满警示闹铃
  9. php支持哪8种数据类型,PHP八种数据类型+使用实例
  10. java定义一个方法,返回一个整数数组的和