Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 509 Bytes

118.-pascals-triangle.md

File metadata and controls

23 lines (19 loc) · 509 Bytes

118. Pascal's Triangle

{% tabs %} {% tab title="Python- 更python一点" %}

class Solution:
    def generate(self, numRows: int) -> List[List[int]]:

        ans = []
        if not numRows: return ans
        if numRows == 1: 
            ans.append([1])
            return ans
        ans.append([1])
        for i in range(1,numRows):
            nums = [x + y for x, y in zip((ans[-1] + [0]),( [0] + ans[-1]))]
            ans.append(nums)

        return ans

{% endtab %} {% endtabs %}