yang_hui_triangle1.py 375 B

12345678910111213141516
  1. from typing import List
  2. def generate(numRows: int) -> List[List[int]]:
  3. ret = list()
  4. for i in range(numRows):
  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 ret
  13. print(generate(5))