---
# System prepended metadata

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

---

###### tags: `leetcode`
# Question 118. Pascal's Triangle
### Description:
Given an integer numRows, return the first numRows of Pascal's triangle.

In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:
### Solution:
DP?
### AC code
```cpp=
#include <vector>
class Solution {
public:
    vector<vector<int>> generate(int tar) {
        vector<vector<int>> vec(tar, vector<int>(1, 0));
        vec[0][0] = 1;
        if(tar==1)
            return vec;
        for(int i = 1 ; i < tar ; i++){
            vec[i].resize(i+1);
            vec[i][0] = vec[i][i] = 1;
            for(int j = 1 ; j < i ; j++){
                if(j<=i-1)
                    vec[i][j] = vec[i-1][j-1]+vec[i-1][j];
                else
                    vec[i][j] = vec[i-1][j-1]+1;
            }
        }
        return vec;
    }
};
```