We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 65d831b commit aaf1d6eCopy full SHA for aaf1d6e
python/minimum_path_sum.py
@@ -0,0 +1,19 @@
1
+# https://leetcode.com/problems/minimum-path-sum/
2
+# T: O(m*n) where n is the number of rows and m is the number of columns
3
+# S: O(1)
4
+
5
+class Solution:
6
+ def minPathSum(self, grid):
7
+ rows, columns = len(grid), len(grid[0])
8
9
+ for column in range(columns - 2, -1, -1):
10
+ grid[rows - 1][column] += grid[rows - 1][column + 1]
11
12
+ for row in range(rows - 2, -1, -1):
13
+ grid[row][columns - 1] += grid[row + 1][columns - 1]
14
15
16
17
+ grid[row][column] += min(grid[row + 1][column], grid[row][column + 1])
18
19
+ return grid[0][0]
0 commit comments