-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathPascal.java
More file actions
42 lines (35 loc) · 968 Bytes
/
Pascal.java
File metadata and controls
42 lines (35 loc) · 968 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
35
36
37
38
39
40
41
42
package Array;
import java.util.ArrayList;
/**
* Author - archit.s
* Date - 21/08/18
* Time - 12:57 AM
*/
public class Pascal {
public ArrayList<ArrayList<Integer>> solve(int A) {
ArrayList<ArrayList<Integer>> result = new ArrayList<>();
for(int i=0;i<A;i++){
result.add(new ArrayList<>());
for(int j=1;j<=i+1;j++){
if(j<=2){
result.get(i).add(1);
}
else{
result.get(i).add(0);
}
}
}
if(A>2){
for(int i=2;i<A;i++){
result.get(i).set(0, 1);
for(int j=1;j<i;j++){
int one = result.get(i-1).get(j-1);
int two = result.get(i-1).get(j);
result.get(i).set(j, one+two);
}
result.get(i).set(i, 1);
}
}
return result;
}
}