Pascal's Triangle II
Last updated
Last updated
Input: rowIndex = 3
Output: [1,3,3,1]Input: rowIndex = 0
Output: [1]Input: rowIndex = 1
Output: [1,1]func getRow(rowIndex int) []int {
if rowIndex == 0 {
return []int{1}
} else if rowIndex == 1 {
return []int{1,1}
} else if rowIndex == 2 {
return []int{1,2,1}
}
res := [][]int{{1}}
for i := 2; i <= rowIndex+1; i++ {
temp := []int{1}
for j := 1; j < i-1; j++ {
temp = append(temp, res[len(res)-1][j]+res[len(res)-1][j-1])
}
temp = append(temp, 1)
res = append(res, temp)
}
return res[rowIndex]
}