add new solutions
This commit is contained in:
parent
0c73608ce5
commit
d798d5e8c9
19 changed files with 661 additions and 4 deletions
26
solutions/1/q118/solution.go
Normal file
26
solutions/1/q118/solution.go
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue