-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion118.java
More file actions
35 lines (32 loc) · 949 Bytes
/
Copy pathQuestion118.java
File metadata and controls
35 lines (32 loc) · 949 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
import java.util.*;
public class Question118
{
public static List<List<Integer>> generate(int numRows)
{
List<List<Integer>> result = new ArrayList<>();
if(numRows == 0)
return result;
List<Integer> row1 = new ArrayList<>();
row1.add(1);
result.add(row1);
for(int i = 1;i<numRows;i++)
{
List<Integer> temp = new ArrayList<>();
temp.add(1);
for(int j = 0;j<result.get(i-1).size()-1;j++)
{
List<Integer> temp2 = result.get(i-1);
temp.add(temp2.get(j)+temp2.get(j+1));
}
temp.add(1);
result.add(temp);
}
return result;
}
public static void main(String[] args)
{
int numRows = 1;
List<List<Integer>> result = generate(numRows);
System.out.println(result);
}
}