Skip to content

Latest commit

 

History

History
36 lines (23 loc) · 619 Bytes

118._pascal's_triangle.md

File metadata and controls

36 lines (23 loc) · 619 Bytes

###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