Class Solution
java.lang.Object
g1201_1300.s1289_minimum_falling_path_sum_ii.Solution
1289 - Minimum Falling Path Sum II.<p>Hard</p>
<p>Given an <code>n x n</code> integer matrix <code>grid</code>, return <em>the minimum sum of a <strong>falling path with non-zero shifts</strong></em>.</p>
<p>A <strong>falling path with non-zero shifts</strong> is a choice of exactly one element from each row of <code>grid</code> such that no two elements chosen in adjacent rows are in the same column.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/08/10/falling-grid.jpg" alt="" /></p>
<p><strong>Input:</strong> arr = [[1,2,3],[4,5,6],[7,8,9]]</p>
<p><strong>Output:</strong> 13</p>
<p><strong>Explanation:</strong> The possible falling paths are: [1,5,9], [1,5,7], [1,6,7], [1,6,8], [2,4,8], [2,4,9], [2,6,7], [2,6,8], [3,4,8], [3,4,9], [3,5,7], [3,5,9] The falling path with the smallest sum is [1,5,7], so the answer is 13.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> grid = [[7]]</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == grid.length == grid[i].length</code></li>
<li><code>1 <= n <= 200</code></li>
<li><code>-99 <= grid[i][j] <= 99</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minFallingPathSum
public int minFallingPathSum(int[][] grid)
-