Java, reduce to 1D array
Similar to "Max Sum of Rectangle No Larger Than K", reduce 2D array to 1D, and find the sub-array sum targeting k.\n\n\npublic int numSubmatrixSumTarget(int[][]
Similar to ["Max Sum of Rectangle No Larger Than K"](https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k/), reduce 2D array to 1D, and find the sub-array sum targeting k.\n\n```\npublic int numSubmatrixSumTarget(int[][] matrix, int target) {\n        int m = matrix.length;\n        int n = matrix[0].length;\n        int[] array = new int[m];\n        int result = 0;\n        for(int i = 0; i < n; i++) { //i is the starting column\n            Arrays.fill(array, 0);\n            for(int j = i; j < n; j++) { //j is the ending column\n                for(int k = 0; k < m; k++) {\n                    array[k] += matrix[k][j];\n                }\n                result += subarraySum(array, target);\n            }\n        }\n        return result;\n    }\n    \n    public int subarraySum(int[] nums, int k) {\n        int sum = 0, result = 0;\n        Map<Integer, Integer> preSum = new HashMap<>();\n        preSum.put(0, 1);\n        \n        for (int i = 0; i < nums.length; i++) {\n            sum += nums[i];\n            if (preSum.containsKey(sum - k)) {\n                result += preSum.get(sum - k);\n            }\n            preSum.put(sum, preSum.getOrDefault(sum, 0) + 1);\n        }\n        \n        return result;\n    }\n```
[]