Skip to content

Commit b59fce9

Browse files
committed
- Unique Paths DaleStudy#273
1 parent 6033e4b commit b59fce9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

unique-paths/ayosecu.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
"""
3+
- Time Complexity: O(mn)
4+
- Space Complexity: O(mn), the "dp" variable
5+
"""
6+
def uniquePaths(self, m: int, n: int) -> int:
7+
dp = [ [1] * n for _ in range(m) ]
8+
9+
# DP Approach
10+
for i in range(1, m):
11+
for j in range(1, n):
12+
dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
13+
14+
return dp[-1][-1]
15+
16+
tc = [
17+
(3, 7, 28),
18+
(3, 2, 3)
19+
]
20+
21+
sol = Solution()
22+
for i, (m, n, e) in enumerate(tc, 1):
23+
r = sol.uniquePaths(m, n)
24+
print(f"TC {i} is Passed!" if r == e else f"TC {i} is Failed! - Expected: {e}, Result: {r}")

0 commit comments

Comments
 (0)