[LeetCode] Pascal's Triangle II
2013-11-12 19:43
393 查看
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return
Note:
Could you optimize your algorithm to use only O(k) extra space?
For example, given k = 3,
Return
[1,3,3,1].
Note:
Could you optimize your algorithm to use only O(k) extra space?
class Solution { public: vector<int> getRow(int rowIndex) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. vector<int> ans; ans.push_back(1); for(int i = 1;i <= rowIndex;i++) { for(int j = i; j > 0;j--) { if(j == i) ans.push_back(1); else ans[j] = ans[j - 1] + ans[j]; } } return ans; } };
相关文章推荐
- leetcode_119——Pascal's Triangle II (简单题,简单的递归)
- 【LeetCode】Pascal's Triangle II (杨辉三角)
- Leetcode 119 Pascal's Triangle II 数论递推
- [LeetCode] Pascal's Triangle II
- [LeetCode] 119. Pascal's Triangle II 杨辉三角 II
- 【leetcode】Pascal's Triangle I & II (middle)
- LeetCode(33)-Pascal's Triangle II
- [Leetcode][JAVA] Pascal's Triangle I, II
- LeetCode(33)-Pascal's Triangle II
- 【leetcode刷题笔记】Pascal's Triangle II
- [LeetCode] Pascal's Triangle II 杨辉三角之二
- 【leetcode】Pascal's Triangle I&II
- LeetCode#119 Pascal's Triangle II
- 【leetcode】Pascal's Triangle II
- Pascal's Triangle II leetcode
- [leetcode]Pascal's Triangle II @ Python
- [leetcode]Pascal's Triangle II
- [LeetCode 119] - 杨辉三角形II(Pascal's Triangle II)
- 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题4
- Leetcode: Pascal's Triangle II