Pascal's Triangle II 第k个数字的排列 杨辉三角形
2015-03-30 20:09
344 查看
Pascal's Triangle II
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> ans(rowIndex+1);//初始化为0 ans[0]=1; for(int i=1;i<=rowIndex;i++) { for(int j=i;j>0;j--) { if(j==i) ans[j]=1; else ans[j]=ans[j-1]+ans[j]; } } return ans; } };
相关文章推荐
- 用1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列,如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连。
- 输出一组数字按由大到小排列
- 该公司笔试题就1个,要求在10分钟内作完。 题目如下:用1、2、2、3、4、5这六个数字,写一个main函数,打印出所有不同的排列, 如:512234、412325等,要求:"4"不能在第三位,"3"与"5"不能相连。
- 数字排列组合
- magento 产品页面销量排序 - 字符属性 按照数字方式排列 - CAST(`sell_number` AS SIGNED)
- 给一个整数数组,对数组中的每个整数中的所有数字按照升序排列(如101排序后为011)请写一个方法,输出排序后的数组中的最大数。 例如有一个数组: 101、132、375,排序后11、123、357,
- 【年少的风】java_Conti有趣的数字排列
- 有两个升序排列的数组A1和A2,给A1开辟的剩余内存有足够空间容纳A1,请实现一个函数,把A2中所有数字插入到A1中,并且是按照升序排列的
- 递归:求螺旋排列数字的矩阵
- POJ1731_2(重复数字排列)
- 数字排列
- 算法爱好者——第k个排列 ? 待解决
- DFS有重复数字的全排列
- java 递归 实现数字的排列组合
- js 纯数字不重复排列的另类方法
- leetcode 440. K-th Smallest in Lexicographical Order 第k个字典序的数字+做不出来
- 数字计算的有序排列的号码出现二分法
- 蓝桥杯 排列数字-今有7对数字
- LinkCode 第k个排列
- JS对象在用于搜索和分析数据上表现出十分便捷的作用,它们甚至连排列数字也不费吹灰之力