leetcode-118. Pascal's Triangle
阿新 • • 發佈:2019-01-24
func generate(numRows int) [][]int {
var arr [][] int;
arr = make([][]int, numRows);
var i, j int;
for i = 0; i < numRows; i++ {
arr[i] = make([]int, i + 1);
for j = 0; j <= i; j++ {
if (j == 0 || i == j) {
arr[i][j] = 1;
} else {
if (i - 1 >= 0 && j - 1 >= 0) {
arr[i][j] += arr[i - 1][j - 1];
}
if (i - 1 >= 0) {
arr[i][j] += arr[i - 1][j];
}
}
}
}
return arr;
}