---
# System prepended metadata

title: Question 119. Pascal's Triangle II
tags: [leetcode]

---

###### tags: `leetcode`
# Question 119. Pascal's Triangle II
### Description:
Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.
### Solution:
DP?
### AC code
CPP Code
```cpp=
class Solution {
public:
    vector<int> getRow(int row) {
        vector<vector <int>> vec(row+1, vector<int>(1,0));
        vec[0][0] = 1;
        if(row==0)
            return vec[0];
        for(int i = 1 ; i < row+1 ; i++){
            vec[i].resize(i+1);
            vec[i][0] = vec[i][i] = 1;
            for(int j = 1 ; j < i ; j++){
                vec[i][j] = vec[i-1][j-1]+vec[i-1][j];
            }
        }
        return vec[row];
    }
};
```
C Code
```c=


/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* getRow(int row, int* returnSize){
    int* arr = (int *)malloc(sizeof(int)*(row+1));
    arr[0] = 1;
    if(row==0){
        *returnSize = row+1;
        return arr;
    }
    int a = 0;
    int b = 1;
    for(int i = 1 ; i <= row ; i++){
        a = 0;
        b = 1;
        for(int j = 0 ; j < i ; j++){
            arr[j] = a + b;
            a = b;
            b = arr[j+1];
        }
        arr[i] = 1;
    }
    *returnSize = row+1;
    return arr;
}

```