Share my c code, easy understand


  • 5
    K

    int* getRow(int rowIndex, int* returnSize) {

    if (rowIndex < 0)
        return NULL;
    
    int *res = (int*)malloc(sizeof(int) * (rowIndex + 1));
    
    for (int row = 0; row <= rowIndex; row++)
        for (int col = row; col >= 0; col--)
            res[col] = (col == 0 || col == row) ? 1 : res[col] + res[col - 1];
    
    *returnSize = rowIndex + 1;
    return res;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.