题目: 将一个m*n的矩阵替换成r*c的矩阵,当不满足的话,返回原矩阵。
思路:easy~ 用队列将所有的数字装起来,再依次取出来放入新数组。
不用额外空间的话,就是所有的数字除以,求余列数得到的就是几行几列~
class Solution {
public int[][] matrixReshape(int[][] nums, int r, int c) {
int row = nums.length;
int column = nums[0].length;
if(row*column != r*c)return nums;
int[][] res = new int[r][c];
for(int i = 0; i < r*c; i ++){
res[i/c][i%c] = nums[i/column][i%column];
}
return res;
}
}