1 class Solution(object): 2 def minFallingPathSum(self, A): 3 while len(A) >= 2: 4 row = A.pop() 5 for i in range(len(row)): 6 A[-1][i] += min(row[max(0,i-1): min(len(row), i+2)]) 7 return min(A[0])
是leetcode1289的基础版本,与leetcode120的思想基本一致。
1 class Solution(object): 2 def minFallingPathSum(self, A): 3 while len(A) >= 2: 4 row = A.pop() 5 for i in range(len(row)): 6 A[-1][i] += min(row[max(0,i-1): min(len(row), i+2)]) 7 return min(A[0])
是leetcode1289的基础版本,与leetcode120的思想基本一致。