118._pascal's_triangle.md 619 字节
Newer Older
K
KEQI HUANG 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
###118. Pascal's Triangle

题目:

<https://leetcode.com/problems/pascals-triangle/>


难度:

Easy


高中数学知识,把行数理理清楚就ok


```
class Solution(object):
    def generate(self, numRows):
        """
        :type numRows: int
        :rtype: List[List[int]]
        """
        res = [[1],[1,1]]
        if numRows < 3:
            return res[:numRows]
        for i in range(3, numRows+1):
            tmp = [1] * i
            for j in range(1,i-1):
                tmp[j] = res[i-2][j-1] + res[i-2][j]
            res.append(tmp)
        return res

                
```