首页 > 其他 > 详细

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

时间:2019-06-08 15:53:23      阅读:102      评论:0      收藏:0      [点我收藏+]

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

参考资料

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

原文:https://www.cnblogs.com/hglibin/p/10990824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!