java.lang.Object
g1001_1100.s1074_number_of_submatrices_that_sum_to_target.Solution

public class Solution extends Object
1074 - Number of Submatrices That Sum to Target.<p>Hard</p> <p>Given a <code>matrix</code> and a <code>target</code>, return the number of non-empty submatrices that sum to target.</p> <p>A submatrix <code>x1, y1, x2, y2</code> is the set of all cells <code>matrix[x][y]</code> with <code>x1 <= x <= x2</code> and <code>y1 <= y <= y2</code>.</p> <p>Two submatrices <code>(x1, y1, x2, y2)</code> and <code>(x1', y1', x2', y2')</code> are different if they have some coordinate that is different: for example, if <code>x1 != x1'</code>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/09/02/mate1.jpg" alt="" /></p> <p><strong>Input:</strong> matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The four 1x1 submatrices that only contain 0.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> matrix = [[1,-1],[-1,1]], target = 0</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> The two 1x2 submatrices, plus the two 2x1 submatrices, plus the 2x2 submatrix.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> matrix = [[904]], target = 0</p> <p><strong>Output:</strong> 0</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= matrix.length <= 100</code></li> <li><code>1 <= matrix[0].length <= 100</code></li> <li><code>-1000 <= matrix[i] <= 1000</code></li> <li><code>-10^8 <= target <= 10^8</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numSubmatrixSumTarget

      public int numSubmatrixSumTarget(int[][] matrix, int target)