Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Karleb
Karleb

Posted on

#1289. Minimum Falling Path Sum II

https://leetcode.com/problems/minimum-falling-path-sum-ii/description/?envType=daily-question&envId=2024-04-26

varminFallingPathSum=function(grid){constminFallingPathSumHelper=function(row,grid){if(row===grid.length){returnnewTriplet(0,0,0);}constnextRowTriplet=minFallingPathSumHelper(row+1,grid);letcurrentTriplet=newTriplet(Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,-1);for(letcol=0;col<grid[0].length;col++){constvalue=grid[row][col]+(col!==nextRowTriplet.minSumIndex?nextRowTriplet.minSum:nextRowTriplet.secondMinSum);if(value<=currentTriplet.minSum){currentTriplet.secondMinSum=currentTriplet.minSum;currentTriplet.minSum=value;currentTriplet.minSumIndex=col;}elseif(value<currentTriplet.secondMinSum){currentTriplet.secondMinSum=value;}}returncurrentTriplet;};constn=grid.length;returnminFallingPathSumHelper(0,grid).minSum;};classTriplet{constructor(minSum,secondMinSum,minSumIndex){this.minSum=minSum;this.secondMinSum=secondMinSum;this.minSumIndex=minSumIndex;}};
Enter fullscreen modeExit fullscreen mode

I do not fully understand this solution. It's a hard problem but not so hard. I really love this solution that I got from leetcode.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I love to make things work.
  • Joined

More fromKarleb

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp