LeetCode 118. Pascal's Triangle
程序员文章站
2022-04-01 11:30:29
...
Problem
Notes
给定层数n,输出n层的杨辉三角形。简单的模拟。
Codes
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int> > ans;
for(int i=0;i<numRows;++i)
{
vector<int> temp;
for(int j=0;j<=i;++j)
{
if(j==0||j==i)
temp.push_back(1);
else
temp.push_back(ans[i-1][j]+ans[i-1][j-1]);
}
ans.push_back(temp);
}
return ans;
}
};
Results
上一篇: 118. Pascal‘s Triangle - Python
下一篇: 试题 基础练习 杨辉三角形
推荐阅读
-
Leetcode No.119 Pascal's Triangle II(c++实现)
-
杨辉三角(pascal's triangle)
-
LeetCode-119. Pascal's Triangle II
-
119. Pascal's Triangle II [杨辉三角形2]
-
119. Pascal's Triangle II
-
leetcode -- 119. Pascal's Triangle II
-
2018.05.03 leetcode #119. Pascal's Triangle II
-
【leetcode】119. Pascal's Triangle II
-
LeetCode 119. Pascal's Triangle II
-
[LeetCode]119. Pascal's Triangle II