首页 > 其他 > 详细

LeetCode#119 Pascal's Triangle II

时间:2015-07-21 22:09:37      阅读:176      评论:0      收藏:0      [点我收藏+]

Problem Definition:

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?

 

Solution:

1 def getRow(rowIndex):
2         pt=[]
3         for rn in range(rowIndex+1):
4             row=[0]*(rn+1)
5             row[0],row[rn]=1,1    
6             for cl in range(1,rn):
7                 row[cl]=pt[cl-1]+pt[cl]
8             pt=row
9         return pt

 

LeetCode#119 Pascal's Triangle II

原文:http://www.cnblogs.com/acetseng/p/4665506.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!