MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / uniquePaths

Method uniquePaths

62-unique-paths/unique-paths.py:4–19  ·  view source on GitHub ↗
(self, m: int, n: int)

Source from the content-addressed store, hash-verified

2
3class Solution:
4 def uniquePaths(self, m: int, n: int) -> int:
5 dp = [[0] * n for _ in range(m)]
6
7 # First row
8 for j in range(n):
9 dp[0][j] = 1
10
11 # First column
12 for i in range(m):
13 dp[i][0] = 1
14
15 for i in range(1, m):
16 for j in range(1, n):
17 dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
18
19 return dp[m - 1][n - 1]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected