【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 ...
随机推荐
- jquery 设置css样式
$("#61dh a").css('color', 多个样式属性 var divcss = { background: '#EEE', width: '478px', mar ...
- Sum Root to Leaf Numbers [LeetCode]
Problem description: http://oj.leetcode.com/problems/sum-root-to-leaf-numbers/ Basic idea: To store ...
- easyUI dialog 弹窗 居中显示
默认情况下应该是在屏幕居中显示的.但是有的时候没有居中只要重新纠正下就可以了 $('#add_dialog').dialog('open'); //打开添加对话框 $('#add_dialog').w ...
- 字符串匹配的sunday算法
sunday算法核心思想:启发式移动搜索步长! SUNDAY 算法描述: 字符串查找算法中,最著名的两个是KMP算法(Knuth-Morris-Pratt)和BM算法(Boyer-Moore).这里介 ...
- 【转】数据库范式(1NF 2NF 3NF BCNF)详解二
以下内容转自:http://jacki6.iteye.com/blog/774889 -------------------------分割线----------------------------- ...
- JBOss启动只能在本机访问的解决办法
环境CentOS6.4_X64 JBoss:5.1.2 eap 启动:JBOSS_HOME/bin/run.sh 在本机可以通过http://localhost:8080访问,而其他机器无论是通过机器 ...
- 如何对HTML进行编码和解码?
答案:这个比较简单//HTML进行编码和解码Console.WriteLine(System.Web.HttpUtility.HtmlEncode("<h1>我是中文字符!< ...
- spring aop编程
1.AOP,面向切面编程(aspect Oriental programing),使用aop,可以将处理切面aspect的代码注入到主程序,通常主程序的主要目的不是处理这些切面aspect,可以防止代 ...
- 北邮新生排位赛1解题报告a-c
<div class="page-header" style="padding-bottom: 9px; margin: 20px 0px 30px; border ...
- C语言中文件的读取和写入
在C语言中写文件 //获取文件指针 FILE *pFile = fopen("1.txt", //打开文件的名称 "w"); // 文件打开方式 如果原来有内容 ...