Skip to content

Instantly share code, notes, and snippets.

@shitu13
Created May 18, 2024 05:15
Show Gist options
  • Save shitu13/eb41e548e93c11aa6a66e5f248ec4676 to your computer and use it in GitHub Desktop.
Save shitu13/eb41e548e93c11aa6a66e5f248ec4676 to your computer and use it in GitHub Desktop.
Pascal's Triangle
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> res(numRows);
for (int i = 0; i < numRows; i++) {
res[i] = vector<int>(i + 1, 1);
for (int j = 1; j < i; j++) {
res[i][j] = res[i-1][j]+ res[i-1][j-1];
}
}
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment