Pascal's Triangle II

来源:互联网 发布:明教喵萝捏脸数据 编辑:程序博客网 时间:2024/06/01 10:07

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;}


0 0