[leetCode刷题笔记]566. Reshape the Matrix

来源:互联网 发布:淘宝联盟购物 编辑:程序博客网 时间:2024/06/05 17:50
public class Solution {    public int[][] matrixReshape(int[][] nums, int r, int c) {        if (nums == null || nums.length == 0 || r * c != nums.length * nums[0].length) return nums;        int[][] result = new int[r][c];                int k = 0;                        for (int i = 0; i < nums.length; i++ ) {            for (int j = 0; j < nums.length; j++) {                result[k / c][k % c] = nums[i][j];                k++;            }        }        return result;            }}