C++ || Easy to Understand
\n\nclass Solution {\npublic:\n\n    int numSubmatrixSumTarget(vector>& A, int k) {\n        // same logic as count subarray with sum k HASHING\n        \n     
![image](https://assets.leetcode.com/users/images/85f0b8b6-ab82-472b-ae76-2db6bf01f1e1_1623670028.9009478.jpeg)\n\nclass Solution {\npublic:\n\n    int numSubmatrixSumTarget(vector<vector<int>>& A, int k) {\n        // same logic as count subarray with sum k HASHING\n        \n        int row = A.size();\n        int col = A[0].size();\n        \n\t\t//Calculating Prefix Sum of Columns\n        for(int i=0;i<row;i++)\n        {\n            for(int j=1;j<col;j++)\n                A[i][j]+=A[i][j-1]; \n        }\n        \n        int count = 0;\n        \n        for(int c1=0;c1<col;c1++)\n        {\n            for(int c2=c1;c2<col;c2++)\n            {\n                unordered_map<int,int>mp;\n                int sum=0;\n                mp[sum]=1;\n                \n                for(int r=0;r<row;r++)\n                {\n                    sum +=A[r][c2] - (c1>0 ? A[r][c1-1] : 0);\n                    \n                    if(mp.find(sum-k)!=mp.end())\n                        count+=mp[sum-k];\n                    \n                    mp[sum]+=1;\n                }\n            }\n        }\n        return count;\n    }\n};
['C', 'C++']