You are viewing a single comment's thread. Return to all comments →
Using one for loop iterating through half of the array
public static int diagonalDifference(List<List<Integer>> arr) { Integer mainDiagonal = 0,secondaryDiagonal = 0; for(int i= 0;i < arr.size() / 2; i++){ mainDiagonal += (Integer) arr.get(i).toArray()[i]; mainDiagonal += (Integer) arr.get(arr.size() - 1 - i).toArray()[arr.size() - 1 - i]; secondaryDiagonal += (Integer) arr.get(arr.size() - 1 - i).toArray()[i]; secondaryDiagonal += (Integer) arr.get(i).toArray()[arr.size() - 1 - i]; } return Math.abs(mainDiagonal-secondaryDiagonal); }
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
Using one for loop iterating through half of the array