【LeetCode OJ】Pascal's Triangle
Prolbem Link:
http://oj.leetcode.com/problems/pascals-triangle/
Just a nest-for-loop...
class Solution:
# @return a list of lists of integers
def generate(self, numRows):
# Initialize the triangle
res = []
for i in xrange(numRows):
res.append([1] * (i+1))
# Compute the triangle row by row
for row in xrange(1, numRows):
for i in xrange(1, row):
res[row][i] = res[row-1][i] + res[row-1][i-1]
# Return
return res
【LeetCode OJ】Pascal's Triangle的更多相关文章
- 【LeetCode OJ】Pascal's Triangle II
Problem Link: http://oj.leetcode.com/problems/pascals-triangle-ii/ Let T[i][j] be the j-th element o ...
- LeetCode OJ 119. Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- LeetCode OJ 118. Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- LeetCode OJ:Pascal's Triangle(帕斯卡三角)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【LeetCode OJ】Triangle
Problem Link: http://oj.leetcode.com/problems/triangle/ Let R[][] be a 2D array where R[i][j] (j < ...
- 【LeetCode OJ】Validate Binary Search Tree
Problem Link: https://oj.leetcode.com/problems/validate-binary-search-tree/ We inorder-traverse the ...
- 【LeetCode OJ】Recover Binary Search Tree
Problem Link: https://oj.leetcode.com/problems/recover-binary-search-tree/ We know that the inorder ...
随机推荐
- hdu---(1054)Strategic Game(最小覆盖边)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 51nod 1043 幸运号码(数位dp)
题目链接:51nod 1043 幸运号码 题解:dp[i][j]表示 i 个数和为 j 的总数(包含0开头情况) dp[i][j] = dp[i-1][j-k] i & 1 :这里用滚动数组节 ...
- Java网络通信
一.基本概念 1.网络程序: 能够接受另一台计算机发送过来的数据或者能够向另一台计算机发送数据的程序叫做网络程序. 2.IP 能够在网络中唯一标示一台主机的编号就是IP 3.端口号 16位数字表示 4 ...
- /etc/crontab文件和crontab -e命令区别
/etc/crontab文件和crontab -e命令区别 1.格式不同 前者 # For details see man 4 crontabs # Example of job definition ...
- express+nodecoffee写passport登录验证实例(一)
项目中要用到passport登录验证,环境如标题样:express框架,coffee模版引擎,node后台 一:建项目 直接用express命令建,虽然默认模版为jade,可以手动换成coffee哦. ...
- cl.exe
http://blog.csdn.net/happyanger6/article/details/7589016
- 在 Visual C# 项目中调用 VBA 中的代码
https://msdn.microsoft.com/zh-cn/library/Bb608613.aspx http://www.cnblogs.com/yangbin1005/archive/20 ...
- 当进入log文件后就卡机
问题:一个目录打开,终端就卡死不动了 Ctrl+c也没用,cat一样没用? 解决办法:用的时间或用的数量删除(时间已经否决掉) ls -t |tail -1000 |xargs rm 原因: log ...
- VS2003编译后的网站如何修改代码
VS2003编译后的网站,如果没有源代码,而要修改里面的代码时,可以以以下方式解决: 反编译dll,把找出cs代码文件,然后重新建一个类项目,把此文件中的代码修改后重新生成dll,放在编译的网站中的b ...
- linux-虚拟机安装
第一步:下载 安装虚拟机! 链接: http://pan.baidu.com/s/1nuGLwsL 密码: 2qdy 第二步:镜像文件! 链接: http://pan.baidu.com/s/1nuG ...