LeetCode: Pascal's Triangle II
来源:互联网 发布:捕鱼软件下载 编辑:程序博客网 时间:2024/06/05 14:21
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<vector<int> >tri(rowIndex+1); vector<int>res; for(int i=0;i<rowIndex+1;++i) { tri[i].resize(i+1); } for(int i=0;i<rowIndex+1;++i) { tri[i][0] = 1; tri[i][i] = 1; } for(int i=1;i<rowIndex+1;++i) { for(int j =1;j<i;++j) { tri[i][j] = tri[i-1][j-1]+tri[i-1][j]; } } for(int i = 0;i<rowIndex+1;++i) { int temp =tri[rowIndex][i]; res.push_back(temp); } return res; }};
0 0
- 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
- [leetcode] Pascal's Triangle II
- LeetCode - Pascal's Triangle II
- LeetCode | Pascal's Triangle II
- Pascal's Triangle II -leetcode
- 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
- PAT_1011. World Cup Betting
- 从影片《点球成金》看大数据如何创造商业奇迹!
- 将elasticsearch设置为windows系统服务
- 打开vmware的centos虚拟机提示锁定文件失败 打不开磁盘
- LeetCode算法题目:Partition List
- LeetCode: Pascal's Triangle II
- win7 64 + xbmc-17.1rc1-Krypton + vs2015编译
- 欢迎使用CSDN-markdown编辑器
- 路由器设置端口映射(局域网通过外网访问)
- Django 常用基本命令
- android 浅入浅出看一下事件传递
- ffmpeg: time_base分析
- 循环队列打印杨辉三角
- 系统思考方式