Files
C/leetcode/src/119.c
Adhiraj 0cd4f6b691 feat: add Leetcode problem 119 (#997)
* added 119

* added 119.c

Co-authored-by: David Leal <halfpacho@gmail.com>
2022-10-28 18:47:45 -05:00

23 lines
492 B
C

/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* getRow(int rowIndex, int* returnSize){
int colIndex = rowIndex + 1;
int* ans = (int*) malloc(sizeof(int) * colIndex);
for (int i = 0; i < colIndex; i++)
{
ans[i] = 1;
}
*returnSize = colIndex;
for (int r = 2; r <= rowIndex; r++)
{
for (int c = r - 1; c > 0; c--)
{
ans[c] = ans[c] + ans[c-1];
}
}
return ans;
}