cjql / algorithm

https://cjql.github.io/algorithm/
1 stars 1 forks source link

LeetCode_Dynamic: minimum-falling-path-sum-ii #11

Open cjql opened 4 years ago

cjql commented 4 years ago

https://leetcode.com/problems/minimum-falling-path-sum-ii/submissions/

C++

Java

Python

class Solution:
    def minFallingPathSum(self, arr: List[List[int]]) -> int:
        for i in range(1,len(arr)):
            r = heapq.nsmallest(2,arr[i-1])
            for j in range(len(arr[0])):
                arr[i][j] += r[1] if arr[i-1][j]==r[0] else r[0]
        return min(arr[-1])

C

C

JavaScript

Ruby

Swift

Go

Scala

Kotlin

Rust

PHP