其他分享
首页 > 其他分享> > LeetCode 566. 重塑矩阵(Reshape the Matrix)

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

作者:互联网

566. 重塑矩阵
566. Reshape the Matrix

题目描述
LeetCode
LeetCode

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;
    }
}

参考资料

标签:Matrix,nums,int,Reshape,566,res,col
来源: https://www.cnblogs.com/hglibin/p/10990824.html