mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 01:44:56 +08:00
Cookbook add 0118 solution
This commit is contained in:
17
leetcode/0118.Pascals-Triangle/118. Pascal's Triangle.go
Normal file
17
leetcode/0118.Pascals-Triangle/118. Pascal's Triangle.go
Normal file
@ -0,0 +1,17 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user