【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 ...
随机推荐
- HTML5自学笔记[ 2 ]新增表单控件和表单属性
新增<input>属性type="email",自动验证,若输入不为邮箱,则不能提交. 新增<input>属性type="tel",在移 ...
- hdu 4405Aeroplane chess(概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 初学java之触发响应事件举例子
设置一个触发响应事件? 比如消息框..... package hello; import javax.swing.*; import project.readerListen; import java ...
- soapUI快速入门(测试一个登录接口)
1.打开soapUI. 2.新建一个项目,实例如下: 点击ok后在soapUI界面左侧会显示出此项目,如图: 2.创建测试用例: a.新建用例组,选择此项目右键,新建一个用例组,如下图: 用例组创建好 ...
- 转:怎样在VMware ESXi上 克隆虚拟机
Cloning virtual machines on VMware ESXi 翻译自http://www.dedoimedo.com/computers/vmware-esxi-clone-mach ...
- tab切换-自动、点击、内容变换
<div class="tab"> <ul class="pics"> ...
- outlook 用宏发邮件
经常发面试邮件,通常只是修改一下收件人邮箱地址,和收件人姓名,其他全部一致,有木有发现每次都用用outlook写邮件很麻烦? 使用宏发邮件,就会不麻烦了,直接修改下称呼,修改下收件人地址,按下F5,就 ...
- 使用HttpClient访问被保护资源
下面的Android应用需要向指定页面发送请求,但该页面并不是一个简单的页面,只有当用户已经登录,而且登录用户的用户名是crazyit.org时才可访问该页面.如果使用HTTPURLConnectio ...
- 计算excel列的名字
#include <iostream> using namespace std; int main() { unsigned int column; cin>> ...
- Android双击返回按钮退出程序
//双击退出事件 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KE ...