Gary Lai
  • Home
  • About
Sign in Subscribe

119. Pascal's Triangle II

Last updated on  Nov 1, 2023

119. Pascal's Triangle II

class Solution:
    def getRow(self, rowIndex: int) -> List[int]:
        if rowIndex == 0:
            return [1]
        prev = self.getRow(rowIndex - 1)
        curr = []
        for i in range(len(prev) - 1):
            curr.append(prev[i] + prev[i+1])
        return [1] + curr + [1]
Previous 118. Pascal's Triangle
Next 557. Reverse Words in a String III
Gary Lai © 2025
  • Sign up
Powered by Ghost