Skip to content

Commit 6a0d031

Browse files
aQuaaQua
aQua
authored and
aQua
committed
118 finish
1 parent af17954 commit 6a0d031

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

Algorithms/0118.pascals-triangle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ For example, given numRows = 5, Return
1414
]
1515
```
1616
## 解题思路
17-
17+
按照 numRows 分情况讨论
1818

1919
## 总结
2020

Algorithms/0118.pascals-triangle/pascals-triangle.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ func generate(numRows int) [][]int {
1919
}
2020

2121
func genNext(p []int) []int {
22-
temp := make([]int, 1)
23-
temp = append(temp, p...)
24-
temp = append(temp, 0)
22+
res := make([]int, 1, len(p)+1)
23+
res = append(res, p...)
2524

26-
for i := len(temp) - 1; i > 0; i-- {
27-
temp[i] += temp[i-1]
25+
for i := 0; i < len(res)-1; i++ {
26+
res[i] += res[i+1]
2827
}
2928

30-
return temp[1:]
29+
return res
3130
}

0 commit comments

Comments
 (0)