-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
33 lines (25 loc) · 836 Bytes
/
solution.java
File metadata and controls
33 lines (25 loc) · 836 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
class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> result = new ArrayList<>();
//Row: 1
result.add(1);
if(rowIndex == 0)
return result;
//Row: 2
result.add(1);
if(rowIndex == 1)
return result;
//Row: 2+
for(int r = 2; r <= rowIndex; r++){
List<Integer> next = new ArrayList<>();
next.add(result.get(0)); //First Entry
//Middle calculations
for(int n = 0; n < result.size() - 1; n++){
next.add(result.get(n) + result.get(n + 1));
}
next.add(result.get(0)); //Last Entry
result = next;
}
return result;
}
}