알고리즘/LeetCode
[LeetCode/easy/Array] Pascal's triangle
녕이
2022. 8. 16. 17:31
728x90
https://leetcode.com/problems/pascals-triangle/
Pascal's Triangle - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
vector<vector<int>> generate(int numRows) {
vector<vector<int>> ans(numRows);
ans[0].push_back(1);
for(int i=1; i<numRows; i++){
for(int j=0; j<=i; j++){
if(j==0 || j==i) ans[i].push_back(1);
else ans[i].push_back((ans[i-1][j-1]+ans[i-1][j]));
}
}
return ans;
}
728x90