We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f831fed commit e4ef80eCopy full SHA for e4ef80e
unique_paths.py
@@ -0,0 +1,30 @@
1
+# A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
2
+#
3
+# The robot can only move either down or right at any point in time.
4
+# The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
5
6
+# How many possible unique paths are there?
7
8
+# Note: m and n will be at most 100.
9
+"""
10
+>>> uniquePaths(3, 2)
11
+3
12
+>>> uniquePaths(7, 3)
13
+28
14
+>>> uniquePaths(0, 0)
15
+0
16
+>>> uniquePaths(0, 2)
17
18
+>>> uniquePaths(2, 0)
19
20
21
+
22
23
+def uniquePaths(m: int, n: int) -> int:
24
+ if not m or not n:
25
+ return 0
26
+ dp = [[1 for col in range(n)] for row in range(m)]
27
+ for i in range(1, m):
28
+ for j in range(1, n):
29
+ dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
30
+ return dp[-1][-1]
0 commit comments