forked from DengWangBao/Leetcode-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascalTriangleII.java
More file actions
22 lines (17 loc) · 498 Bytes
/
PascalTriangleII.java
File metadata and controls
22 lines (17 loc) · 498 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.ArrayList;
import java.util.List;
public class PascalTriangleII {
public List<Integer> getRow(int rowIndex) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i <= rowIndex; i++) {
int prev = 1;
for (int j = 1; j < list.size(); j++) {
int n = list.get(j) + prev;
prev = list.get(j);
list.set(j, n);
}
list.add(1);
}
return list;
}
}