public class Solution {
public int[,] MatrixReshape(int[,] nums, int r, int c) {
var row = nums.GetLength();
var col = nums.GetLength(); if (row * col != r * c)
{
return nums;
}
else
{
var ary = new int[r, c];
var list = new List<int>(); for (int i = ; i < row; i++)
{
for (int j = ; j < col; j++)
{
list.Add(nums[i, j]);
}
} var k = ;
for (int i = ; i < r; i++)
{
for (int j = ; j < c; j++)
{
ary[i, j] = list[k++];
}
} return ary;
}
}
}

https://leetcode.com/problems/reshape-the-matrix/#/description

leetcode566的更多相关文章

  1. [Swift]LeetCode566. 重塑矩阵 | Reshape the Matrix

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  2. leetcode566. Reshape the Matrix

    https://leetcode.com/problems/reshape-the-matrix/description/ public int[][] matrixReshape(int[][] n ...

  3. 算法21----重塑矩阵 LeetCode566

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

  4. Leetcode566.Reshape the Matrix重塑矩阵

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

  5. LeetCode 566. 重塑矩阵(Reshape the Matrix)

    566. 重塑矩阵 566. Reshape the Matrix 题目描述 LeetCode LeetCode LeetCode566. Reshape the Matrix简单 Java 实现 c ...

随机推荐

  1. centos7最小化安装后配置笔记

    一.安装wget(步骤2备用) yum install wget -y 二.切换yum源为阿里云 备份旧源: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum ...

  2. HDU2043 密码

    解题思路:10分钟AC,不解释,so easy! #include<cstdio> #include<cstring> #include<algorithm> us ...

  3. 让ASP.NET第一次请求不变慢

    网页开发者早期最常遇到一个问题,当网站布署到IIS时候,每当IIS或是Application Pool重启后,第一位进入网站的使用者,其体验往往第一个反应就是网站很慢,然后就一直询问IT为什么网站这么 ...

  4. HihoCoder 1044 垃圾清理 (优化:状态压缩)

    状态压缩·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在兑换到了喜欢的奖品之后,便继续起了他们的美国之行,思来想去,他们决定乘坐火车前往下一座城市— ...

  5. BZOJ1857 Scoi2010 传送带 【三分】

    BZOJ1857 Scoi2010 传送带 Description 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P ...

  6. 什么是Docker—无服务器计算服务

    什么是Docker https://mp.weixin.qq.com/s?__biz=MzU0Mzk1OTU2Mg==&mid=2247483881&idx=1&sn=aa27 ...

  7. ORACLE PL/SQL:触发器

    ORACLE PL/SQL 触发器 本篇主要内容如下: 8.1 触发器类型 8.1.1 DML触发器 8.1.2 替代触发器 8.1.3 系统触发器 8.2 创建触发器 8.2.1 触发器触发次序 8 ...

  8. openssl 查看证书细节

    打印证书的过期时间 openssl x509 -in signed.crt -noout -dates 打印出证书的内容: openssl x509 -in cert.pem -noout -text ...

  9. JS脚本不能运行

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/moqiang02/article/details/25898295 这段时间在做前端的动态页面,出了 ...

  10. jQuery的页面初始化操作写法

    $(document).ready(function(){ alert("第一种方法."); }); $(function(){ alert("第二种方法.") ...