1、这道题一次提交就AC了;

2、以前用C语言实现的话,初始化二维数组全部为0,然后每行第一个元素为1,只需要用a[i][j] = a[i-1][j]+a[i-1][j-1]就可以了;

3、在Python中难点应该就是每行的第一个元素和最后一个元素,最后一个元素通过判断j==i就可以区分了;

 class Solution:
# @return a list of lists of integers
def generate(self, numRows):
ret = []
for i in range(numRows):
ret.append([1])
for j in range(1,i+1):
if j==i:
ret[i].append(1)
else:
ret[i].append(ret[i-1][j]+ret[i-1][j-1])
return ret

leetcode:Pascal's Triangle【Python版】的更多相关文章

  1. [leetcode]Pascal's Triangle @ Python

    原题地址:https://oj.leetcode.com/problems/pascals-triangle/ 题意: Given numRows, generate the first numRow ...

  2. LeetCode:Pascal's Triangle I II

    LeetCode:Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For examp ...

  3. [leetcode]Pascal's Triangle II @ Python

    原题地址:https://oj.leetcode.com/problems/pascals-triangle-ii/ 题意: Given an index k, return the kth row ...

  4. LeetCode Pascal's Triangle && Pascal's Triangle II Python

    Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, given ...

  5. LeetCode——Pascal's Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  6. [LeetCode] 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, ...

  7. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  8. 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题4

    当我们需要改变数组的值时,如果从前往后遍历,有时会带来很多麻烦,比如需要插入值,导致数组平移,或者新的值覆盖了旧有的值,但旧有的值依然需要被使用.这种情况下,有时仅仅改变一下数组的遍历方向,就会避免这 ...

  9. LeetCode - Pascal's Triangle II

    题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return ...

  10. LeetCode: Pascal's Triangle II 解题报告

    Pascal's Triangle II Total Accepted: 19384 Total Submissions: 63446 My Submissions Question Solution ...

随机推荐

  1. linux中tomcat内存溢出PermGen space

    1.若是部署时候,一个tomcat下面项目越少越好,单独为一个项目配置tomcat(在客户给你充足的端口的情况下) 2.在维护的时候,若一个tomcat下放多个项目的话,这时候可以把所有jar包放在t ...

  2. robot framework学习笔记1之_环境安装(win7)

    一.简介 Robotframework是基于Python的自动化测试框架.使用关键字驱动的测试方法,自带丰富的库函数可直接引用,可使用Java/Python进行功能库扩展,测试用例使用TSV/HTML ...

  3. MVC5 学习笔记 controller

    主要参考书籍<ASP.NET MVC5 高级编程(第5版) > 作者:Jon Galloway等 1. MVC 表示 模型-视图-控制器.MVC是一种用于开发应用程序的模式,具备良好的架构 ...

  4. Hibernate---运行原理

    Hibernate---运行原理

  5. ASCII码表(0-127 ) C中的转义字符

    所有的ASCII码都可以用“\”加数字(一般是8进制数字)来表示.而C中定义了一些字母前加"\"来表示常见的那些不能显示的ASCII字符,如\0,\t,\n等,就称为转义字符,因为 ...

  6. POJ 3220 位运算+搜索

    转载自:http://blog.csdn.net/lyhypacm/article/details/5813634 DES:相邻的两盏灯状态可以互换,给出初始状态.询问是否能在三步之内到达.如果能的话 ...

  7. call、apply的应用

    call方法: 语法:call([thisObj[,arg1[, arg2[,   [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call 方法可以用来 ...

  8. Time-python

    1 datetime   datetime是Python处理日期和时间的标准库   1.1 datetime.datetime datetime.datetime.now()              ...

  9. AE项目打包

    Holinz AE项目打包 打包详细信息:Setup Factory 7.0打包软件,VS2005+AE92下的Winform项目1.依赖项:    Dot Net Framework20    AO ...

  10. L219 China's office workers consider further education, training essential

    More than 90 percent of China's office workers consider on-the-job training and continuing education ...