Java prefix sum + hashmap
\n    public int numSubmatrixSumTarget(int[][] mx, int t) {\n        int res = 0, m = mx.length, n = mx[0].length;\n        for (int i = 0;i < m; i++) {\n      
```\n    public int numSubmatrixSumTarget(int[][] mx, int t) {\n        int res = 0, m = mx.length, n = mx[0].length;\n        for (int i = 0;i < m; i++) {\n            for (int j = 1; j < n; j++) {\n                mx[i][j] += mx[i][j - 1];\n            }\n        }\n        for (int l = 0; l < n; l++) {\n            for (int r = l; r < n; r++) {\n                Map<Integer, Integer> map = new HashMap<>(); \n                map.put(0, 1);// init empty sub mx;\n                for (int i = 0, sum = 0; i < m; i++) {\n                    sum += (mx[i][r] - (l == 0 ? 0 : mx[i][l - 1]));\n                    res += map.getOrDefault(sum - t, 0);\n                    map.put(sum, map.getOrDefault(sum, 0) + 1);\n                }\n            }\n        }\n        return res;\n    }\n```
[]