8000 :sparkles: Added solution to 119 · ninefive/awesome-golang-leetcode@9fd63c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fd63c9

Browse files
author
Sathish Babu
committed
✨ Added solution to 119
1 parent c232b08 commit 9fd63c9

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/0119.Pascals-Triangle-II/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
66
## Description
77

8+
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.
9+
10+
Note that the row index starts from 0.
11+
12+
In Pascal's triangle, each number is the sum of the two numbers directly above it.
13+
814
**Example 1:**
915

1016
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
17+
Input: 3
18+
Output: [1,3,3,1]
1319
```
1420

1521
## 题意
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(rowIndex int) []int {
4+
if rowIndex == 0 {
5+
return []int{1}
6+
}
7+
pt := make([]int, 0)
8+
for i := 0; i < rowIndex; i++ {
9+
tmp := make([]int, 0)
10+
tmp = append(tmp, 1)
11+
for j := 1; j < i+1; j++ {
12+
tmp = append(tmp, pt[j]+pt[j-1])
13+
}
14+
tmp = append(tmp, 1)
15+
pt = tmp
16+
}
17+
return pt
518
}

src/0119.Pascals-Triangle-II/Solution_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs int
14+
expect []int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase", 0, []int{1}},
17+
{"TestCase", 3, []int{1, 3, 3, 1}},
18+
{"TestCase", 5, []int{1, 5, 10, 10, 5, 1}},
1919
}
2020

2121
// 开始测试

0 commit comments

Comments
 (0)
0