mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-07-21 08:25:10 +00:00
23 lines
492 B
C
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;
|
|
}
|