(numRows int)
| 1 | package pascals_triangle_118 |
| 2 | |
| 3 | func 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 | } |
no outgoing calls