Leetcode 重塑矩阵

```输入:
nums =
[[1,2],
[3,4]]
r = 1, c = 4

[[1,2,3,4]]

```

```输入:
nums =
[[1,2],
[3,4]]
r = 2, c = 4

[[1,2],
[3,4]]

```

1. 给定矩阵的宽和高范围在 [1, 100]。
2. 给定的 r 和 c 都是正数。

``````/**
* Return an array of arrays of size *returnSize.
* The sizes of the arrays are returned as *returnColumnSizes array.
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
*/
int** matrixReshape(int** nums, int numsSize, int* numsColSize, int r, int c, int* returnSize, int** returnColumnSizes){
int i, j , k, l;
int **ret;

if(numsSize * *numsColSize != r * c) {
*returnSize = numsSize;
*returnColumnSizes = numsColSize;

return nums;
}

ret = malloc(sizeof(int*)*r);

i = 0;
j = 0;

for(k = 0; k < r; k++) {
ret[k] = malloc(sizeof(int) * c);
for(l = 0; l < c; l++) {
ret[k][l] = nums[i][j++];
if(j >= *numsColSize) {
j = 0;
i++;
}
}
}

*returnSize = r;
*returnColumnSizes = malloc(sizeof(int) * r);
for(i = 0; i < r; i++)
(*returnColumnSizes)[i] = c;

return ret;
}``````

;