Least Runtime Solution
\nclass Solution:\n    def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:\n        n, m = len(matrix), len(matrix[0])\n        answer
```\nclass Solution:\n    def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:\n        n, m = len(matrix), len(matrix[0])\n        answer = 0\n        \n        for i in range(n):\n            for j in range(1, m):\n                matrix[i][j] += matrix[i][j - 1]\n                \n        for j in range(m):\n            for k in range(j, m):\n                d, c = {0: 1}, 0\n                for i in range(n):\n                    c += matrix[i][k] - (matrix[i][j - 1] if j else 0)\n                    if c - target in d:\n                        answer += d[c - target]\n                    d[c] = d[c] + 1 if c in d else 1  \n        return answer\n```
['Matrix']