We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
出处 LeetCode 算法第118题 给定一个非负整数 *numRows,*生成杨辉三角的前 numRows 行。 在杨辉三角中,每个数是它左上方和右上方的数的和。 示例: 输入: 5 输出: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
出处 LeetCode 算法第118题
给定一个非负整数 *numRows,*生成杨辉三角的前 numRows 行。
在杨辉三角中,每个数是它左上方和右上方的数的和。
示例:
输入: 5 输出: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
双重循环
var generate = function (numRows) { var result = []; for (var i = 0; i < numRows; i++) { var temp = []; for (var j = 0; j <= i; j++) { if (j == 0 || j == i) { temp.push(1); } else { temp.push(result[i - 1][j - 1] + result[i - 1][j]); } } result.push(temp); } return result; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
习题
思路
双重循环
解答
The text was updated successfully, but these errors were encountered: