hourGlassChallenge
This commit is contained in:
parent
d6d3ccd4df
commit
34b2a56e02
BIN
HourGlass.class
Normal file
BIN
HourGlass.class
Normal file
Binary file not shown.
34
HourGlass.java
Normal file
34
HourGlass.java
Normal file
@ -0,0 +1,34 @@
|
||||
public class HourGlass {
|
||||
|
||||
/*
|
||||
* 1 1 1 0 0 0
|
||||
* 0 1 0 0 0 0
|
||||
* 1 1 1 0 0 0
|
||||
* 0 0 0 0 0 0
|
||||
* 0 0 0 0 0 0
|
||||
* 0 0 0 0 0 0
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int[][] ar = { { 1, 1, 1, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0 }, { 1, 1, 1, 0, 0, 0 }, { 0, 0, 2, 4, 4, 0 },
|
||||
{ 0, 0, 0, 2, 0, 0 }, { 0, 0, 1, 2, 4, 0 } };
|
||||
System.out.println(sumInt(ar));
|
||||
}
|
||||
|
||||
private static int sumInt(int[][] arr) {
|
||||
int rows = arr.length;
|
||||
int columns = arr[0].length;
|
||||
|
||||
int total = -63;
|
||||
for (int i = 0; i < rows - 2; i++) {
|
||||
for (int j = 0; j < columns - 2; j++) {
|
||||
int currentSum = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j]
|
||||
+ arr[i + 2][j + 1] + arr[i + 2][j + 2];
|
||||
total = Math.max(total, currentSum);
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user