Last active
May 7, 2020 11:17
-
-
Save Gosilama/bd32d4e770b757cc7f479995856243d4 to your computer and use it in GitHub Desktop.
Given a square matrix, calculate the absolute difference between the sums of its diagonals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int diagonalDifference(List<List<Integer>> arr) { | |
int primarySum = 0; | |
int secondarySum = 0; | |
for (int i = 0; i < arr.size(); i++) { | |
primarySum += arr.get(i).get(j); | |
secondarySum += arr.get(i).get(arr.size() - j - 1); | |
} | |
return Math.abs(primarySum - secondarySum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment