프로그래밍/LeetCode
[LeetCode][Python3] 118. Pascal's Triangle
snoopybox
2018. 10. 17. 01:25
Problem :
https://leetcode.com/problems/pascals-triangle/description/
My Solution :
class Solution:
def generate(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
ans = []
for i in range(1, numRows+1):
row = [1]
for j in range(1, i):
row.append(sum(ans[i-2][j-1:j+1]))
ans.append(row)
return ans