Description
Given an integer numRows, return the first numRows of Pascal's triangle.
In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:
My solution
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
array = [1] * 30
array[0] = [1]
array[1] = [1,1]
for i in range(2,30):
array[i] = [1]
for k in range(i-1):
array[i].append(array[i - 1][k] + array[i - 1][k + 1])
array[i].append(1)
return array[0:numRows]
문제 출처 : https://leetcode.com/problems/pascals-triangle/
Pascal's Triangle - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
'Algorithm > Daily Coding Tests Challenge' 카테고리의 다른 글
[Leetcode] Medium : Network Delay time (0) | 2021.10.13 |
---|---|
[Leetcode] Easy: Pascal's Triangle 2 (0) | 2021.10.10 |
[Leetcode] Easy: Climbing Stairs (0) | 2021.10.10 |
[Leetcode] Median : Find First and Last Position of Element in Sorted Array (0) | 2021.10.09 |
[Leetcode] Hard : Median of Two Sorted Array (0) | 2021.10.09 |