<LeetCode><Easy> 118 Pascal's Triangle II
来源:互联网 发布:网络零售交易额指什么 编辑:程序博客网 时间:2024/05/18 02:22
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?
#Python2 TimeOut
#递归
偏移求和【0】+L(k) 与L(k)+【0】--> L(k+1)
class Solution(object): def getRow(self, rowIndex): """ :type rowIndex: int :rtype: List[int] """ get=lambda k:map(lambda x,y:x+y,get(k-1)+[0],[0]+get(k-1)) if k>1 else [1,1] if k==1 else [1] get(rowIndex)
#是组合数的列写
class Solution(object): def getRow(self, rowIndex): """ :type rowIndex: int :rtype: List[int] """ fatorial=lambda x:fatorial(x-1)*x if x>1 else 1 combination=lambda m,n:fatorial(m)/fatorial(n)/fatorial(m-n) if rowIndex%2: fore=[combination(rowIndex,i) for i in range(rowIndex/2+1)] return fore+fore[::-1] else: fore=[combination(rowIndex,i) for i in range(rowIndex/2+1)] return fore+fore[::-1][1:]
0 0
- <LeetCode><Easy> 118 Pascal's Triangle II
- Leetcode[Easy] - Pascal's Triangle II
- <LeetCode><Easy> 118 Pascal's Triangle
- leetcode 118[easy]---Pascal's Triangle
- Leetcode[Easy] - Pascal's Triangle
- Leetcode 119. Pascal's Triangle II (Easy) (cpp)
- LeetCode-Easy刷题(28) Pascal's Triangle II
- LeetCode.118(119) Pascal's Triangle && II
- [Leetcode 118 and 119, Easy] Pascal's Triangle (I and 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
- matlab中的eps功能
- html使用Frameset快速方便制作导航栏
- 由阿里一道笔试题引发的思考/ String
- ping 错误信息返回分析
- opencv学习笔记(十三)——数据结构
- <LeetCode><Easy> 118 Pascal's Triangle II
- iOS开发多线程篇—自定义NSOperation
- MySQL找出表中重复字段的内容
- SolrCloud4.9+zookeeper在CentOS上的搭建与安装
- Android 编译重要参数 LOCAL_MODULE_TAGS
- CocoaPods
- VM-based OpenStack Neutron Framework解析
- ios 下CGImageCreateWithImageInRect 内存泄露
- swift 2.0 延展 Extension