566. 重塑矩阵
566. Reshape the Matrix
LeetCode566. Reshape the Matrix简单
Java 实现
class Solution {
public int[][] matrixReshape(int[][] nums, int r, int c) {
int row = nums.length, col = nums[0].length;
if (row * col != 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 / col][i % col];
}
return res;
}
}
参考资料