Skip to content

Instantly share code, notes, and snippets.

@romanoffs
Created November 29, 2019 22:48
Show Gist options
  • Save romanoffs/f0b68d833e4977d2ce225fc2531e9718 to your computer and use it in GitHub Desktop.
Save romanoffs/f0b68d833e4977d2ce225fc2531e9718 to your computer and use it in GitHub Desktop.
public static int diagonalDifference(int size, List<List<Integer>> arr) {
int sum1, sum2;
sum1 = IntStream
.range(0, size)
.map(i -> arr.get(i).get(i))
.sum();
sum2 = IntStream
.range(0, size)
.map(i -> arr.get(i).get((size - 1) - i))
.sum();
return Math.abs(sum1 - sum2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment