yang_hui_triangle2.py 370 B

123456789101112131415
  1. from typing import List
  2. def getRow(rowIndex: int) -> List[int]:
  3. ret = list()
  4. for i in range(rowIndex + 1):
  5. res = list()
  6. for j in range(0, i + 1):
  7. if j == 0 or j == i:
  8. res.append(1)
  9. else:
  10. res.append(ret[i - 1][j - 1] + ret[i - 1][j])
  11. ret.append(res)
  12. return res
  13. print(getRow(6))