Concise python solution

  • 0
    def generate(k):
        res = []
        for i in range(0, k):
            curr = list(res[-1]) if len(res) else []
            for i in range(1, len(curr)):
                curr[i] = res[-1][i - 1] + res[-1][i]
            res.append(curr + [1])
        return res

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.