> For the complete documentation index, see [llms.txt](https://private-26.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://private-26.gitbook.io/notes/coding/easy/118.-pascals-triangle.md).

# 118. Pascal's Triangle

\#cc #string

***

## Intuition

*

## Approach

*

## Complexity

| Space Complexity | Time Complexity |
| ---------------- | --------------- |
| $$\text{O}()$$   | $$\text{O}()$$  |

## Code

```java
public List<List<Integer>> generate(int numRows) {
	List<List<Integer>> fin = new ArrayList<>();

	if(numRows >= 1) fin.add(Arrays.asList(1));
	if(numRows >= 2)  fin.add(Arrays.asList(1,1));

	List<Integer> prev = Arrays.asList(1,1);
	for(int i = 3; i <= numRows; ++i ) {
		List<Integer> curr = new ArrayList<>();
		curr.add(1);

		for(int j =0; j +1 < prev.size(); ++j ) {
		   curr.add(prev.get(j) + prev.get(j+1)); 
		}

		curr.add(1);

		prev = curr;

		fin.add(curr);

	}

	return fin;
}
```
