add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent 0c73608ce5
commit d798d5e8c9
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
19 changed files with 661 additions and 4 deletions

View file

@ -0,0 +1,26 @@
package q118
func generate(numRows int) [][]int {
buf := make([]int, numRows*(1+numRows)/2)
p := 0
take := func(n int) []int {
ret := buf[p : p+n]
p = p + n
return ret
}
ret := make([][]int, 0, numRows)
for i := 1; i <= numRows; i++ {
row := take(i)
row[0] = 1
row[len(row)-1] = 1
for j := 1; j < len(row)-1; j++ {
row[j] = ret[i-2][j-1] + ret[i-2][j]
}
ret = append(ret, row)
}
return ret
}
var _ = generate