- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
Latest commit
44 lines (36 loc) · 1.14 KB
/
Copy pathSolution.java
File metadata and controls
44 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
importjava.io.*;
importjava.math.*;
importjava.security.*;
importjava.text.*;
importjava.util.*;
importjava.util.concurrent.*;
importjava.util.regex.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
Scannerscan = newScanner(System.in);
intarr[][] = newint[6][6];
for (introw = 0; row < 6; row++) {
for (intcol = 0; col < 6; col++) {
arr[row][col] = scan.nextInt();
}
}
scan.close();
System.out.println(maxHourglass(arr));
}
publicstaticintmaxHourglass(int [][] arr) {
intmax = Integer.MIN_VALUE;
for (introw = 0; row < 4; row++) {
for (intcol = 0; col < 4; col++) {
intsum = findSum(arr, row, col);
max = Math.max(max, sum);
}
}
returnmax;
}
privatestaticintfindSum(int [][] arr, intr, intc) {
intsum = arr[r+0][c+0] + arr[r+0][c+1] + arr[r+0][c+2]
+ arr[r+1][c+1] +
arr[r+2][c+0] + arr[r+2][c+1] + arr[r+2][c+2];
returnsum;
}
}