# Pascal Triangle

Description:

Given numRows, generate the first numRows of Pascal‘s triangle.

For example, given numRows = 5,
Return

```[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]Thoughts:第一种：直观的想法就是，我们计算第n+1行的值，它的头尾都是1，中间的值T[n+1][i] = T[n][i-1]+T[i];根据这个想法得到如下的java代码：```
```class Solution {
public List<List<Integer>> generate(int numRnows){
List<List<Integer>> result = new ArrayList();
if(numRnows<=0){
return new ArrayList(){{}};
}
for(int i = 1;i<=numRnows;i++){
List lists = new ArrayList();

if(i == 1){
}else{
for(int j = 1; j<i-1;j++){
}
}

}
return result;
}

}```

```package easy.array;

import java.util.ArrayList;
import java.util.List;

public class GeneratePascal {
public List<List<Integer>> generate(int numRnows){
List<List<Integer>> allrows = new ArrayList<List<Integer>>();
ArrayList<Integer> row = new ArrayList<Integer>();
for(int i=0;i<numRnows;i++)
{
for(int j=1;j<row.size()-1;j++)
row.set(j, row.get(j)+row.get(j+1));
}
return allrows;
}

public static void main(String[] args){
int numRnows = 10;
GeneratePascal ge = new GeneratePascal();
List<List<Integer>> f = ge.generate(numRnows);
for(int i= 0; i<numRnows;i++){
System.out.println(f.get(i));
}
}
}```

Pascal Triangle

(0)
(0)

0条