Minimum Falling Path Sum LeetCode solution in Python
1class Solution:2def minFallingPathSum(self, matrix: List[List[int]]) -> int:3for row in range(1, len(matrix)):4for col in range(0, len(matrix[row])):5if col == 0:6matrix[row][col] += min(7matrix[row - 1][col + 1], matrix[row - 1][col]8)9elif col == len(matrix[row]) - 1:10matrix[row][col] += min(11matrix[row - 1][col - 1], matrix[row - 1][col]12)13else:14matrix[row][col] += min(15matrix[row - 1][col - 1],16matrix[row - 1][col],17matrix[row - 1][col + 1],18)1920return min(matrix[-1])