Prefix Sum  Easy C++
\nclass Solution {\npublic:\n   int numSubmatrixSumTarget(vector<vector<int>>& A, int target) {\n        int res = 0, m = A.size(), n = A[0].size();\n        fo
```\nclass Solution {\npublic:\n   int numSubmatrixSumTarget(vector<vector<int>>& A, int target) {\n        int res = 0, m = A.size(), n = A[0].size();\n        for (int i = 0; i < m; i++)\n            for (int j = 1; j < n; j++)\n                A[i][j] += A[i][j - 1];  // prefix sum of matrix row wise \n\n        unordered_map<int, int> counter;\n        for (int i = 0; i < n; i++) {\n            for (int j = i; j < n; j++) {\n                counter = {{0,1}};\n                int cur = 0;\n                for (int k = 0; k < m; k++) {\n                    cur += A[k][j] - (i > 0 ? A[k][i - 1] : 0);\n                    res += counter.find(cur - target) != counter.end() ? counter[cur - target] : 0; \n                    counter[cur]++;\n                }\n            }\n        }\n        return res;\n    }\n};\n```
[]