-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathSolution.java
30 lines (25 loc) · 856 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// github.com/RodneyShag
import java.util.Scanner;
/* O(N^2) runtime. O(1) space */
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int primaryDiagonal = 0;
int secondaryDiagonal = 0;
for (int row = 0; row < N; row++) {
for (int col = 0; col < N; col++) {
int value = scan.nextInt();
if (row == col) {
primaryDiagonal += value;
}
if (row + col == N - 1) {
secondaryDiagonal += value;
}
}
}
scan.close();
int absoluteDifference = Math.abs(primaryDiagonal - secondaryDiagonal);
System.out.println(absoluteDifference);
}
}