Reshape the Matrix

给一个2d数组,和r和c, 返回重构后的int[r][c].

class Solution {
    public int[][] matrixReshape(int[][] nums, int r, int c) {
        if(r*c != nums.length * nums[0].length)
            return nums;
        int[][] res = new int[r][c];
        int k = 0;
        int t = 0;
        for(int i = 0; i < nums.length; i++) {
            for(int j = 0; j < nums[0].length; j++) {
                res[k][t] = nums[i][j];
                if(t < c - 1) {
                    t++;
                }
                else {
                    t = 0;
                    k++;
                }
            }
        }
        return res;
    }
}