[leetcode, python] Pascal's Triangle II 杨辉三角
2016-12-23 00:27
204 查看
问题描述:
解决方案:
思路说明:
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1].
解决方案:
class Solution(object): def getRow(self, rowIndex): """ :type rowIndex: int :rtype: List[int] """ result = [1] for num in range(rowIndex): result = [sum(i) for i in zip([0] + result, result + [0])] return result
思路说明:
下一行的结果 = 上一行复制两份,错位相加(空位补0)。如: [1,1] = [0,1] + [1,0] [1,2,1] = [0,1,1] + [1,1,0] [1,3,3,1] = [0,1,2,1] + [1,2,1,0] ...
相关文章推荐
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- [leetcode, python] Pascal's Triangle II 杨辉三角
- LeetCode119. Pascal's Triangle II-python(easy)
- [LeetCode][119. Pascal's Triangle II][easy]Java实现,杨辉三角
- [LeetCode By Python]119. Pascal's Triangle II
- [leetCode 118 & 119] Pascal's Triangle I && II (杨辉三角问题)
- Leetcode#119. Pascal's Triangle II(杨辉三角II)
- LeetCode-119:Pascal's Triangle II (返回杨辉三角指定行)
- 119. Pascal's triangle II Leetcode Python
- (LeetCode)Pascal's Triangle II --- 杨辉三角进阶(滚动数组思想)
- Leetcode 119. Pascal's Triangle II 杨辉三角2 解题报告