java.lang.Object
g2401_2500.s2428_maximum_sum_of_an_hourglass.Solution

public class Solution extends Object
2428 - Maximum Sum of an Hourglass.<p>Medium</p> <p>You are given an <code>m x n</code> integer matrix <code>grid</code>.</p> <p>We define an <strong>hourglass</strong> as a part of the matrix with the following form:</p> <p><img src="https://assets.leetcode.com/uploads/2022/08/21/img.jpg" alt="" /></p> <p>Return <em>the <strong>maximum</strong> sum of the elements of an hourglass</em>.</p> <p><strong>Note</strong> that an hourglass cannot be rotated and must be entirely contained within the matrix.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/08/21/1.jpg" alt="" /></p> <p><strong>Input:</strong> grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]</p> <p><strong>Output:</strong> 30</p> <p><strong>Explanation:</strong> The cells shown above represent the hourglass with the maximum sum: 6 + 2 + 1 + 2 + 9 + 2 + 8 = 30.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/08/21/2.jpg" alt="" /></p> <p><strong>Input:</strong> grid = [[1,2,3],[4,5,6],[7,8,9]]</p> <p><strong>Output:</strong> 35</p> <p><strong>Explanation:</strong> There is only one hourglass in the matrix, with the sum: 1 + 2 + 3 + 5 + 7 + 8 + 9 = 35.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>m == grid.length</code></li> <li><code>n == grid[i].length</code></li> <li><code>3 <= m, n <= 150</code></li> <li><code>0 <= grid[i][j] <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxSum

      public int maxSum(int[][] grid)