Python Basics簡単

Nth row of Pascal Triangle

Detailed guide and Python implementation for the 'Nth row of Pascal Triangle' problem.

問題提起

簡単

Write a function pascal_row(n) that returns the nth row of Pascal's Triangle as a list of integers using recursion. Rows are 0-indexed: row 0 is [1], row 1 is [1, 1], row 2 is [1, 2, 1], etc. Each element is the sum of the two elements directly above it in the previous row.

制約
  • 0 <= n <= 30

Example 1
Input
n = 0
Output
[1]
Explanation

The 0th row of Pascal's Triangle is just [1].

Example 2
Input
n = 4
Output
[1, 4, 6, 4, 1]
Explanation

Row 3 is [1,3,3,1]. Row 4: 1, (1+3)=4, (3+3)=6, (3+1)=4, 1.

Example 3
Input
n = 2
Output
[1, 2, 1]
Explanation

Row 1 is [1,1]. Row 2: 1, (1+1)=2, 1.

Need a Hint?
Consider using Recursion-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

解決する準備はできましたか?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。