Created
May 18, 2024 05:15
-
-
Save shitu13/eb41e548e93c11aa6a66e5f248ec4676 to your computer and use it in GitHub Desktop.
Pascal's Triangle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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