EASY JAVA SOLUTION || PREFIX SUM
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n\n# Code\n\nclass Solution {\n    public int numSubmatrixSumTarget(int[][] matrix, 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n\n# Code\n```\nclass Solution {\n    public int numSubmatrixSumTarget(int[][] matrix, int target) {\n        int result = 0;\n        //Calculating prefix sum in all rows\n        for(int i=0;i<matrix.length;i++){\n            for(int j=1;j<matrix[0].length;j++){\n                matrix[i][j] = matrix[i][j-1] + matrix[i][j]; \n            }\n        }\n\n        //applying prefix Sum - HashMap technique\n        for(int i=0;i<matrix.length;i++){\n            int[] arr = new int[matrix[0].length+1];\n            for(int j = i;j<matrix.length;j++){\n                for(int k=0;k<matrix[0].length;k++){\n                    arr[k+1] = arr[k+1] + matrix[j][k];\n                }\n                result += targetSum(arr,target);\n            }\n        }\n        return result;\n    }\n\n    // method for prefix sum - HashMap techinique\n    private int targetSum(int[] arr,int k){\n        int result = 0;\n        Map<Integer,Integer> map = new HashMap<>();\n        for(int i=0;i<arr.length;i++){\n            if(map.containsKey(arr[i]-k))\n                result += map.get(arr[i]-k);\n                map.put(arr[i],map.getOrDefault(arr[i],0) + 1);\n        }\n        return result;\n    }\n}\n```
['Java']