我的算法之路22-- 帕斯卡三角形

class Solution(object):
    def generate(self, numRows):
        """
        :type numRows: int
        :rtype: List[List[int]]
        """
        if not numRows:
            return []
        ln=[[1]]
        la=[1]
        for i in range(numRows-1):       
            lb=[1]
            for j in range(1,len(la)):
                lb.append(la[j]+la[j-1])
            lb.append(1)
            ln.append(lb[:])
            la=lb[:]
        return ln

猜你喜欢

转载自blog.csdn.net/joaming/article/details/89478856