File tree Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
public List <List <Integer >> generate (int numRows ) {
3
- List <List <Integer >> ans = new ArrayList <>();
3
+ List <List <Integer >> result = new ArrayList <>();
4
4
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 )));
13
10
}
14
- System .out .println (list );
15
- ans .add (list );
11
+ result .add (temp );
16
12
}
17
- return ans ;
13
+ return result ;
18
14
}
19
15
}
You can’t perform that action at this time.
0 commit comments