91% Faster and Memory efficient solution
\t\n\tclass Solution:\n    def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:\n        m = len(matrix)\n        n = len(matrix[0])\n 
\t\n\tclass Solution:\n    def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:\n        m = len(matrix)\n        n = len(matrix[0])\n        \n        ans = 0\n        \n        for i in range(m): # enum upper bound\n            total = [0] * n\n            \n            for j in range(i, m): # enum lower bound\n                for c in range(n):\n                    # update each row\'s sum\n                    total[c] += matrix[j][c]\n                    \n                ans += self.subarrSum(total, target)\n                \n                \n        return ans\n    \n    \n    \n    def subarrSum(self, nums, k):\n        hashmap = defaultdict(int)\n        hashmap[0] = 1\n\n        cnt = presum = 0\n        for x in nums:\n            presum += x \n\n            if presum - k in hashmap:\n                cnt += hashmap[presum-k]\n\n            hashmap[presum] += 1\n\n        return cnt
['Python']