Practice/Meta/Leetcode 1074. Number of Submatrices That Sum to Target
CodingMust
Given a 2D integer matrix and a target integer, determine how many non-empty rectangular submatrices exist within the matrix such that the sum of all elements in the submatrix equals the target value.
A submatrix is defined by choosing a contiguous block of rows and columns from the original matrix. The submatrix can be as small as a single cell or as large as the entire matrix.
Example 1:
` Input: matrix = [[0,1,0],[1,1,1],[0,1,0]], target = 0 Output: 4 Explanation: The four submatrices that sum to 0 are:
Example 2:
` Input: matrix = [[1,-1],[-1,1]], target = 0 Output: 5 Explanation: Five submatrices sum to 0:
Example 3:
Input: matrix = [[904]], target = 0 Output: 0 Explanation: The single cell has value 904, which does not equal 0.