Skip to content

Commit 9cf905c

Browse files
authored
Update Pascal's Triangle.java
1 parent 96c31eb commit 9cf905c

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Easy/Pascal's Triangle.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
class Solution {
22
public List<List<Integer>> generate(int numRows) {
3-
List<List<Integer>> ans = new ArrayList<>();
3+
List<List<Integer>> result = new ArrayList<>();
44
for (int i = 0; i < numRows; i++) {
5-
List<Integer> list = new ArrayList<>();
6-
for (int j = 0; j < i + 1; j++) {
7-
if (j == 0 || j == i) {
8-
list.add(1);
9-
}
10-
else {
11-
list.add(ans.get(i - 1).get(j - 1) + ans.get(i - 1).get(j));
12-
}
5+
List<Integer> temp = new ArrayList<>();
6+
for (int j = 0; j <= i; j++) {
7+
temp.add(
8+
(j == 0 || j == i) ? 1 :
9+
(result.get(i - 1).get(j - 1) + result.get(i - 1).get(j)));
1310
}
14-
System.out.println(list);
15-
ans.add(list);
11+
result.add(temp);
1612
}
17-
return ans;
13+
return result;
1814
}
1915
}

0 commit comments

Comments
 (0)