Skip to content

Commit 5660e19

Browse files
authored
Create minimum-falling-path-sum.py
1 parent 5aba016 commit 5660e19

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Python/minimum-falling-path-sum.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(n^2)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minFallingPathSum(self, A):
6+
"""
7+
:type A: List[List[int]]
8+
:rtype: int
9+
"""
10+
for i in xrange(1, len(A)):
11+
for j in xrange(len(A[i])):
12+
A[i][j] += min(A[i-1][max(j-1, 0):j+2])
13+
return min(A[-1])

0 commit comments

Comments
 (0)