Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1]
.
https://leetcode.com/problems/pascals-triangle-ii/
/**
* Return an array of size *returnSize.
* Note: The returned array must be malloced, assume caller calls free().
*/
int* getRow(int rowIndex, int* returnSize) {
int *res = NULL;
if(rowIndex < 0){
*returnSize = 0;
return NULL;
}
res = malloc(sizeof(int)*(rowIndex + 1));
memset(res, 0, sizeof(int)*(rowIndex + 1));
res[0] = 1;
for(int i = 1; i < rowIndex + 1; i++)
for(int j = i; j >= 1; j--)
res[j] += res[j - 1];
*returnSize = rowIndex + 1;
return res;
}