MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / generate

Function generate

pascals_triangle_118/solution.go:3–18  ·  view source on GitHub ↗
(numRows int)

Source from the content-addressed store, hash-verified

1package pascals_triangle_118
2
3func generate(numRows int) [][]int {
4 res := make([][]int, 0, numRows)
5 for r := 0; r < numRows; r++ {
6 row := make([]int, r+1)
7 row[0], row[len(row)-1] = 1, 1
8
9 // Build the new row by using values from the previous row
10 for c := 1; c < len(row)-1; c++ {
11 row[c] = res[r-1][c-1] + res[r-1][c]
12 }
13
14 res = append(res, row)
15 }
16
17 return res
18}

Callers 1

Test_generateFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_generateFunction · 0.68