(int[][] matrix)
| 11 | } |
| 12 | |
| 13 | public static int maxSubMatrix(int[][] matrix) { |
| 14 | int rowCount = matrix.length; |
| 15 | int colCount = matrix[0].length; |
| 16 | |
| 17 | int[] partialSum = new int[colCount]; |
| 18 | int maxSum = 0; // Max sum is an empty matrix |
| 19 | |
| 20 | for (int rowStart = 0; rowStart < rowCount; rowStart++) { |
| 21 | clearArray(partialSum); |
| 22 | |
| 23 | for (int rowEnd = rowStart; rowEnd < rowCount; rowEnd++) { |
| 24 | for (int i = 0; i < colCount; i++) { |
| 25 | partialSum[i] += matrix[rowEnd][i]; |
| 26 | } |
| 27 | |
| 28 | int tempMaxSum = maxSubArray(partialSum, colCount); |
| 29 | |
| 30 | // if you want to track the coordinates, add code here to do that |
| 31 | maxSum = Math.max(maxSum, tempMaxSum); |
| 32 | } |
| 33 | } |
| 34 | return maxSum; |
| 35 | } |
| 36 | |
| 37 | public static int maxSubArray(int array[], int N) { |
| 38 | int maxSum = 0; |
no test coverage detected