-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascalTriangleII.java
More file actions
34 lines (28 loc) · 860 Bytes
/
Copy pathPascalTriangleII.java
File metadata and controls
34 lines (28 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Link: https://leetcode.com/problems/pascals-triangle-ii/description/
class Solution {
public List<Integer> getRow(int rowIndex) {
List<List<Integer>> list = new ArrayList<>();
List<Integer> lw = new ArrayList<>();
lw.add(1);
list.add(lw);
if(rowIndex == 0) {
return list.get(0);
}
List<Integer> lw1 = new ArrayList<>();
lw1.add(1);
lw1.add(1);
list.add(lw1);
for(int i = 2; i < rowIndex+1; i++) {
List<Integer> l = new ArrayList<>();
List<Integer> p = list.get(i-1);
// манипуляции
l.add(1);
for(int j = 1; j < i; j++) {
l.add(p.get(j-1) + p.get(j));
}
l.add(1);
list.add(l);
}
return list.getLast();
}
}