【LeetCode with Python】 Pascal's Triangle II
2014-07-06 15:17
459 查看
博客域名:http://www.xnerv.wang
原题页面:https://oj.leetcode.com/problems/pascals-triangle-ii/
题目类型:
难度评价:★
本文地址:/article/1377503.html
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return
Note:
Could you optimize your algorithm to use only O(k) extra space?
原题页面:https://oj.leetcode.com/problems/pascals-triangle-ii/
题目类型:
难度评价:★
本文地址:/article/1377503.html
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: # @return a list of lists of integers def getRow(self, rowIndex): if rowIndex <= 0: return [1] elif 1 == rowIndex: return [1, 1] elif rowIndex >= 2: need_rowsnum = rowIndex - 1 last_row = [1, 1] for i in range(0, need_rowsnum): new_row = [1] for j in range(1, len(last_row)): new_row.append(last_row[j - 1] + last_row[j]) new_row.append(1) last_row = new_row return last_row
相关文章推荐
- 【LeetCode with Python】 Pascal's Triangle
- 【leetcode】Pascal's Triangle II (python)
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 【LeetCode with Python】 Regular Expression Matching
- 【LeetCode with Python】 String to Integer (atoi)
- 【LeetCode with Python】 Swap Nodes in Pairs
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 【LeetCode with Python】 Reverse Integer
- 【LeetCode with Python】 Permutations
- 【LeetCode with Python】 LRU Cache
- 【LeetCode with Python】 Same Tree
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 【LeetCode with Python】 Remove Element
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 从Python & Zope到Java with EJB 3 & JBoss SEAM
- 【LeetCode with Python】 Decode Ways