mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 01:15:57 +08:00
18 lines
340 B
Go
18 lines
340 B
Go
package leetcode
|
|
|
|
func generate(numRows int) [][]int {
|
|
result := [][]int{}
|
|
for i := 0; i < numRows; i++ {
|
|
row := []int{}
|
|
for j := 0; j < i+1; j++ {
|
|
if j == 0 || j == i {
|
|
row = append(row, 1)
|
|
} else if i > 1 {
|
|
row = append(row, result[i-1][j-1]+result[i-1][j])
|
|
}
|
|
}
|
|
result = append(result, row)
|
|
}
|
|
return result
|
|
}
|