[leetcode, python] Pascal's Triangle II 杨辉三角
来源:互联网 发布:双代号网络图软件 编辑:程序博客网 时间:2024/05/29 17:02
问题描述:
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]...
0 0
- [leetcode, python] Pascal's Triangle II 杨辉三角
- 【LeetCode】Pascal's Triangle II (杨辉三角)
- [LeetCode]-Pascal's Triangle I&II 杨辉三角问题
- 【LeetCode】Pascal's Triangle (杨辉三角)
- 【LeetCode】Pascal's Triangle (杨辉三角)
- (LeetCode)Pascal's Triangle --- 杨辉三角
- LeetCode OJ 之 Pascal's Triangle II (杨辉三角II )
- 【Leetcode】【python】Pascal's Triangle, Pascal's Triangle II
- [leetCode 118 & 119]Pascal's Triangle I && II (杨辉三角问题)
- (LeetCode)Pascal's Triangle II --- 杨辉三角进阶(滚动数组思想)
- Leetcode 119. Pascal's Triangle II 杨辉三角2 解题报告
- [LeetCode][119. Pascal's Triangle II][easy]Java实现,杨辉三角
- LeetCode-119:Pascal's Triangle II (返回杨辉三角指定行)
- 【LeetCode with Python】 Pascal's Triangle II
- 【leetcode】Pascal's Triangle II (python)
- 119. Pascal's triangle II Leetcode Python
- Pascal's Triangle II Leetcode Python java
- LeetCode Pascal's Triangle 打印杨辉三角
- Leetcode Best Time to Buy and Sell Stock II
- 【java】数组
- 关于Opencv中Rect和Rectangle函数
- Qt主界面获取对话框数据
- 简易的Android绘图程序
- [leetcode, python] Pascal's Triangle II 杨辉三角
- poj 3273(二分)区间的最大值
- mc集群写入恍惚问题排查
- MySQL 报错Error Code: 1290. The MySQL server is running with the --secure-file-priv option
- Android工具类---dp,px,sp之间的转换
- PHPCMS v9 tag标签页调用缩略图的方法
- 【记忆化搜索】滑雪(dp模板)
- 指针的指针有什么用
- Redis slots迁移丢key问题排查