LEETCODE--Pascal's Triangle
来源:互联网 发布:电子仿真软件列表 编辑:程序博客网 时间:2024/06/06 04:52
Given numRows, generate the first numRows of Pascal’s triangle.
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
Subscribe to see which companies asked this question
class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>> finsh; if(numRows == 0) return finsh; if(numRows >= finsh.size() + 1) { vector<int> add; finsh.push_back(add); } finsh[0].push_back(1); if(numRows == 1) return finsh; else{ for(int i = 1; i < numRows; i++){ if(i == finsh.size()) { vector<int> add; finsh.push_back(add); } finsh[i].push_back(1); for(int j = 1; j <= i; j++){ if(finsh[i].size() == i) finsh[i].push_back(1); else{ int x = finsh[i-1][j-1]; int y = finsh[i-1][j]; int elem = x + y; finsh[i].push_back(elem); } } } return finsh; } }};
0 0
- 【Leetcode】Pascal's Triangle (Pascal)
- LeetCode Pascal's Triangle
- [Leetcode] Pascal's Triangle
- LeetCode: Pascal's Triangle
- [LeetCode] Pascal's Triangle
- 【leetcode】Pascal's Triangle
- LeetCode - Pascal's Triangle
- [LeetCode]Pascal's Triangle
- Leetcode: Pascal's Triangle
- Pascal's Triangle --Leetcode
- LeetCode-Pascal's Triangle
- [leetcode] Pascal's Triangle
- LeetCode - Pascal's Triangle
- 【leetcode】Pascal's Triangle
- LeetCode | Pascal's Triangle
- Pascal's Triangle -leetcode
- [leetcode]Pascal's Triangle
- Leetcode Pascal's Triangle
- LocalBroadcastManager—创建更高效、更安全的广播
- 三维绘图之OpenGL和Qt的结合
- [LeetCode] Longest Palindromic Substring
- LightOJ 1013 - Love Calculator(dp)
- win7 eclipse: Could not open Selected VM debug port (8700)
- LEETCODE--Pascal's Triangle
- [213]House Robber II
- 用贪心算法解决背包问题
- 欢迎使用CSDN-markdown编辑器
- memmem()和strstr()函数
- lightoj 1297 Largest Box
- 华为OJ题目(三):字符统计
- LightOJ 1017 - Brush (III)(dp)
- Jump Game (Medium)