[leetcode][array] Pascal's Triangle II
来源:互联网 发布:js拼接json字符串 编辑:程序博客网 时间:2024/06/05 16:44
题目:
Given an index k, return the kth row of the Pascal's triangle.
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) { vector<int> res; if(rowIndex < 0) return res; res.push_back(1); for(int i = 1; i <= rowIndex; ++i){ vector<int> curRow; for(int j = 0; j <= i; ++j){ if(0 == j || i == j) curRow.push_back(1); else curRow.push_back(res[j-1]+res[j]); } res = curRow; } return res; }};
0 0
- LeetCode[Array]: Pascal's Triangle II
- [leetcode][array] Pascal's Triangle II
- leetcode 119 Pascal's Triangle II(array)
- LeetCode-Array-119. Pascal's Triangle II
- Array Pascal's Triangle II
- [Array]Pascal's Triangle II
- 118、119 pascal's triangle I、II---Array-LeetCode
- 【leetcode】Array—— Pascal's Triangle and Pascal's Triangle II(118/119)
- LeetCode[Array]: Pascal's Triangle
- [leetcode][array] Pascal's Triangle
- LeetCode Pascal's Triangle II
- LeetCode: Pascal's Triangle II
- [LeetCode] Pascal's Triangle II
- [Leetcode] Pascal's Triangle II
- 【leetcode】Pascal's Triangle II
- LeetCode - Pascal's Triangle II
- Leetcode: Pascal's Triangle II
- LeetCode-Pascal's Triangle II
- tld标签文件配置问题
- 碰撞检测
- hdu4939 Stupid Tower Defense stl map
- 调整数组顺序使奇数位于偶数前面
- javascript中substring和substr的用法
- [leetcode][array] Pascal's Triangle II
- JDBC连接MySql
- C++中的typeid关键字
- [android]AIDL详解
- Mybatis Integer类型,值为0被认为是空字符串的解决办法
- C# 多线程
- 程序1.1 重排字符 (rearrange.c)
- PyMongo安装和使用
- IOS開發之——objectForKey與valueForKey在NSDictionary中的差異