Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 9fe763a

Browse files
committed
created solution for problem63
1 parent b1ab5f9 commit 9fe763a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

problem63/Solution.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def uniquePaths(self, m: int, n: int) -> int:
3+
# Memoization
4+
pathCache = [[0] * n for _ in range(m)]
5+
6+
def move(i,j):
7+
if i == m-1 and j == n-1: return 1
8+
if pathCache[i][j]: return pathCache[i][j]
9+
10+
paths = 0
11+
12+
# Go down if row < m-1
13+
if i < m-1: paths += move(i+1, j)
14+
15+
# Go up if column < n-1
16+
if j < n-1: paths += move(i, j+1)
17+
18+
pathCache[i][j] = paths
19+
return paths
20+
21+
return move(0,0)

0 commit comments

Comments
 (0)