Java Using HashMap
\nclass Solution {\n\tpublic int numSubmatrixSumTarget(int[][] arr, int target) {\n\t\tint n = arr.length;\n\t\tint m = arr[0].length;\n\t\tint count = 0;\n\t\t
```\nclass Solution {\n\tpublic int numSubmatrixSumTarget(int[][] arr, int target) {\n\t\tint n = arr.length;\n\t\tint m = arr[0].length;\n\t\tint count = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] temp = new int[m];\n\t\t\tfor (int row = i; row < n; row++) {\n\t\t\t\tfor (int col = 0; col < m; col++) {\n\t\t\t\t\ttemp[col] += arr[row][col];\n\t\t\t\t}\n\t\t\t\tcount += helper(temp, target);\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n\n\tpublic int helper(int[] arr, int target) {\n\t\tHashMap<Integer, Integer> map = new HashMap<>();\n\t\tmap.put(0, 1);\n\t\tint count = 0, sum = 0;\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tsum += arr[i];\n\t\t\tcount += map.getOrDefault(sum - target, 0);\n\t\t\tmap.put(sum, map.getOrDefault(sum, 0) + 1);\n\t\t}\n\t\treturn count;\n\t}\n}\n```
['Java']