serega1112

931

Jan 26th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. class Solution:
  2.     def minFallingPathSum(self, A: List[List[int]]) -> int:
  3.         n = len(A)
  4.        
  5.         for i in range(1, n):
  6.             for j in range(n):
  7.                 center = A[i-1][j]
  8.                 left = A[i-1][j-1] if j > 0 else center
  9.                 right = A[i-1][j+1] if j < n - 1 else center
  10.                 A[i][j] += min(left, center, right)
  11.                
  12.         return min(A[n-1])
Advertisement
Add Comment
Please, Sign In to add comment