---
# System prepended metadata

title: '[Easy] 118. Pascal''s Triangle'
tags: [LeetCode-Easy]

---

<!-- 
<b>
-->

# <span style="color: green">[Easy]</span> 118. Pascal's Triangle

##  Problem Summary
Given a number of height, return the Pascal's Triangle the form of list.

## 💡 Approach
The easy approach is to iterate for all layer, assigned them to be the sum of two elements from upper layer.

## </> Code
```python
class Solution:
    def generate(self, numRows: int) -> List[List[int]]:
        tri = [[1]]

        for i in range(1, numRows):
            tmp = [1]
            for j in range(1, i):
                tmp.append(tri[i-1][j] + tri[i-1][j-1])
            tmp.append(1)
            tri.append(tmp)

        return tri
```

## 🕒 Runtime
Time: `0ms` | `Beats 100%`
Memory: `17.86MB` | `Beats 37.13%`

## 📈 Complexity

<b>Assume that: </b>
- `n` is the given number

<b>The overall complexity:</b>
- Time Complexity: `O(n²)`
- Space Complexity: `O(n²)`
