62. Unique Paths¶
Edited by Charles
Medium · Python · Dynamic Programming
Problem
Read the original problem on LeetCode.
The official page contains the problem statement, examples, and constraints.
Explanation, examples & other approaches
Core idea
Recall 70. Climbing Stairs for the core idea. Emphasis: the initialization. Consider the boundaries, say grid[0][j] and grid[i][0], there is only one way to reach the places along these boundaries.
Original study notes follow, including intermediate snippets and earlier attempts.
Note:
- Recall 70. Climbing Stairs for the core idea.
- Emphasis: the initialization. Consider the boundaries, say grid[0][j] and grid[i][0], there is only one way to reach the places along these boundaries.
Study record
| Field | Value |
|---|---|
| Attempts | 1 |
| Mastery | ❚ |
| The Latest Attempt | February 2, 2026 |
Python solution¶
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
grid = [[1] * n for _ in range(m)]
for i in range(1, m):
for j in range(1, n):
grid[i][j] = grid[i - 1][j] + grid[i][j - 1]
return grid[-1][-1]