Easy C++ Soln || Analogous to number of subarray sum k || Explanied
\nclass Solution {\npublic:\n    //just like number of subarray with sum k only dimension is 2\n    int numSubmatrixSumTarget(vector<vector<int>>& mat, int targ
```\nclass Solution {\npublic:\n    //just like number of subarray with sum k only dimension is 2\n    int numSubmatrixSumTarget(vector<vector<int>>& mat, int target) {\n        vector<vector<int>> pre=mat;\n        // row wise sum\n        for(int r=1;r<mat.size();r++){\n            for(int i=0;i<mat[0].size();i++){\n                pre[r][i]+=pre[r-1][i];\n            }\n        }\n        unordered_map<int,int> mp;\n        int ans=0;\n        for(int r=0;r<mat.size();r++){\n            for(int i=r;i<mat.size();i++){\n                int sum=0;\n                mp.clear();\n                mp[sum]++;\n                for(int j=0;j<mat[0].size();j++){\n                    sum+=pre[i][j]-(r>0?pre[r-1][j]:0);\n                    if(mp.count(sum-target))ans+=mp[sum-target];\n                    mp[sum]++;\n                }\n            }\n        }\n        return ans;\n       \n    }\n};\n```
['C']