You are viewing a single comment's thread. Return to all comments →
public static int maxHourGlassValue(List<List<Integer>> arr){ Integer result = Integer.MIN_VALUE; for(int i = 0; i < arr.size(); i++){ List<Integer> inner_list = arr.get(i); for(int j = 0; j < inner_list.size(); j++){ try{ List<Integer> horizon_1 = arr.get(i-1); List<Integer> horizon_2 = arr.get(i+1); int calculated_value = inner_list.get(j) + horizon_1.get(j) + horizon_1.get(j-1) + horizon_1.get(j+1) + horizon_2.get(j) + horizon_2.get(j-1) + horizon_2.get(j+1); if(calculated_value > result) result=calculated_value; }catch(Exception e){ } } } return result; }
Avoided IndexOutOfBounds with try catch
Seems like cookies are disabled on this browser, please enable them to open this website
Java 2D Array
You are viewing a single comment's thread. Return to all comments →
Avoided IndexOutOfBounds with try catch