问题遇到的现象和发生背景
https://leetcode-cn.com/problems/pascals-triangle/solution/
问题相关代码,请勿粘贴截图
class Solution {
public:
vector<vector<int>> generate(int numRows) {
int i = numRows;
int j = numRows;
int dp[i][j]; //代表的是第i行第j列的元素是多少
vector<vector<int>> st;
vector<int> s;
for(int i = 0;i<numRows;i++)
dp[i][0] = 1;
for(int j = 0;j<numRows;j++)
dp[j][j+1] = 0;
for(int i = 1;i<=numRows;i++){
for(int j = 1;j<=i+1;j++){
dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
s.push_back(dp[i,j]);
}
st.push_back(s);
}
return st;
}
};