Skip to content

Commit

Permalink
Create 0118-pascals-triangle.go
Browse files Browse the repository at this point in the history
  • Loading branch information
AP-Repositories authored Dec 31, 2022
1 parent 627c245 commit 7cd5ecd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions go/0118-pascals-triangle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
func generate(rowIndex int) [][]int {
if rowIndex == 0 {
return [][]int{{1}}
} else {
return getAllRow(rowIndex - 1)
}
}

func getAllRow(rowIndex int) [][]int {
if rowIndex == 0 {
return [][]int{{1}}
}
ListPrec := getAllRow(rowIndex - 1)
Len := len(ListPrec[len(ListPrec) - 1])
ListPrec = append(ListPrec, []int{1})
for i := 0; i < Len - 1; i++ {
ListPrec[len(ListPrec) - 1] = append(
ListPrec[len(ListPrec) - 1],
ListPrec[len(ListPrec) - 2][i] + ListPrec[len(ListPrec) - 2][i + 1])
}
ListPrec[len(ListPrec) - 1] = append(ListPrec[len(ListPrec) - 1], 1)
return ListPrec
}

0 comments on commit 7cd5ecd

Please sign in to comment.