8000 refactor 118 · tobeexpert/Leetcode@3d1d9c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d1d9c9

Browse files
refactor 118
1 parent 4bcdce6 commit 3d1d9c9

File tree

1 file changed

+18
-17
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+18
-17
lines changed
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.fishercoder.solutions;
22

3-
43
import java.util.ArrayList;
54
import java.util.List;
65

@@ -22,24 +21,26 @@
2221
*/
2322
public class _118 {
2423

24+
public static class Solution1 {
2525
public List<List<Integer>> generate(int numRows) {
26-
List<List<Integer>> result = new ArrayList();
27-
int len = 1;
28-
for (int i = 0; i < numRows; i++) {
29-
List<Integer> row = new ArrayList(len);
30-
row.add(1);
31-
if (i > 0) {
32-
List<Integer> lastRow = result.get(i - 1);
33-
for (int j = 1; j < len; j++) {
34-
if (j < lastRow.size()) {
35-
row.add(lastRow.get(j - 1) + lastRow.get(j));
36-
}
37-
}
38-
row.add(1);
26+
List<List<Integer>> result = new ArrayList();
27+
int len = 1;
28+
for (int i = 0; i < numRows; i++) {
29+
List<Integer> row = new ArrayList(len);
30+
row.add(1);
31+
if (i > 0) {
32+
List<Integer> lastRow = result.get(i - 1);
33+
for (int j = 1; j < len; j++) {
34+
if (j < lastRow.size()) {
35+
row.add(lastRow.get(j - 1) + lastRow.get(j));
3936
}
40-
result.add(row);
41-
len++;
37+
}
38+
row.add(1);
4239
}
43-
return result;
40+
result.add(row);
41+
len++;
42+
}
43+
return result;
4444
}
45+
}
4546
}

0 commit comments

Comments
 (0)
0