You are viewing a single comment's thread. Return to all comments →
Java.
public static int diagonalDifference(List<List<Integer>> arr) { int[] sumDiagonal = new int[2]; for(int i = 0; i < arr.size(); i++) { List<Integer> columnsRow = arr.get(i); Integer leftElement = columnsRow.get(i); Integer rightElement = columnsRow.get(columnsRow.size() - i - 1); sumDiagonal[0] += leftElement; sumDiagonal[1] += rightElement; } return Math.abs(sumDiagonal[0] - sumDiagonal[1]); }
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 →
Java.