✅Easy C++ Solution Similar to Sub Array Sum
Intuition\n- Find prefix sum for each row.\n- Then find subarray sum for each pair of column and check if it\'s equals to the target or not.\n\n# Approach\n Des
# Intuition\n- Find prefix sum for each row.\n- Then find subarray sum for each pair of column and check if it\'s equals to the target or not.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\nint subarraySum(vector<int>& nums, int k) {\n\n        ios_base::sync_with_stdio(0);\n        cin.tie(0);\n        cout.tie(0);\n        \n        int cnt = 0, curr_sum = 0;\n        unordered_map<int, int>mp;\n        for(int i=0; i<nums.size(); i++)\n        {\n            curr_sum += nums[i];\n\n            if(curr_sum == k)cnt++;\n            if(mp.find(curr_sum - k) != mp.end())\n            {\n                cnt += mp[curr_sum - k];\n            }\n\n            mp[curr_sum]++;\n        }\n\n        return cnt;\n    }\n\n    \n    int numSubmatrixSumTarget(vector<vector<int>>& mat, int target) {\n\n        int count=0;\n        int n = mat.size();\n        int m = mat[0].size();\n\n        for(int i=0; i<n; i++){\n\t\t\t\n            vector<int> sum(m, 0);\n            for(int j=i; j<n; j++){\n                for(int k=0; k<m; k++){\n                    sum[k] += mat[j][k];\n                }\n                count += subarraySum(sum, target);\n            }\n        }\n       \n    return count;\n        \n    }\n};\n```
['Array', 'Hash Table', 'Matrix', 'Prefix Sum', 'C++']