java.lang.Object
g0901_1000.s0931_minimum_falling_path_sum.Solution

public class Solution extends Object
931 - Minimum Falling Path Sum.<p>Medium</p> <p>Given an <code>n x n</code> array of integers <code>matrix</code>, return <em>the <strong>minimum sum</strong> of any <strong>falling path</strong> through</em> <code>matrix</code>.</p> <p>A <strong>falling path</strong> starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position <code>(row, col)</code> will be <code>(row + 1, col - 1)</code>, <code>(row + 1, col)</code>, or <code>(row + 1, col + 1)</code>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/11/03/failing1-grid.jpg" alt="" /></p> <p><strong>Input:</strong> matrix = [[2,1,3],[6,5,4],[7,8,9]]</p> <p><strong>Output:</strong> 13</p> <p><strong>Explanation:</strong> There are two falling paths with a minimum sum as shown.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/11/03/failing2-grid.jpg" alt="" /></p> <p><strong>Input:</strong> matrix = [[-19,57],[-40,-5]]</p> <p><strong>Output:</strong> -59</p> <p><strong>Explanation:</strong> The falling path with a minimum sum is shown.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == matrix.length == matrix[i].length</code></li> <li><code>1 <= n <= 100</code></li> <li><code>-100 <= matrix[i][j] <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minFallingPathSum

      public int minFallingPathSum(int[][] matrix)