Easy Approach Using Map  and prefix sum 🔥
\n# Complexity\n- Time complexity:\n    O(mmn)\n- Space complexity:\n    O(N)\n\n# Code\n\nclass Solution {\npublic:\n    int getCount(vector<int> &prefix, int 
\n# Complexity\n- Time complexity:\n    O(m*m*n)\n- Space complexity:\n    O(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int getCount(vector<int> &prefix, int target){\n        unordered_map<int,int> m;\n        int sum = 0;\n        int ans = 0;\n        m[0]=1;\n        for(auto i : prefix){\n            sum += i;\n            if(m[sum-target] > 0){\n                ans += m[sum-target];\n            }\n            m[sum]++;\n        }\n        return ans;\n    }\n    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {\n        int m = matrix.size();\n        int n = matrix[0].size();\n        int ans = 0;\n        for(int i=0;i<m; i++){\n            vector<int> prefix(n, 0);\n            for(int j=i; j<m; j++){\n                for(int k=0;k<n;k++){\n                    prefix[k] += matrix[j][k];\n                }\n                ans += getCount(prefix, target);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']