-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagonalDifference.java
More file actions
45 lines (34 loc) · 1.04 KB
/
Copy pathDiagonalDifference.java
File metadata and controls
45 lines (34 loc) · 1.04 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.HackerRank;
import java.util.Scanner;
public class DiagonalDifference {
/*
* Hacker Rank Algorithm Question - Diagonal Difference Solution
*
* Solved Date : 2019-07-25
* Author : TK Lee
*
* Source : https://www.hackerrank.com/challenges/diagonal-difference/problem
*/
public static void main (String[] args){
int left = 0;
int right = 0;
int val = 0;
Scanner sc = new Scanner(System.in);
int rowNum = sc.nextInt();
//Test Cases
//int[][] matrix = {{11, 2, 4}, {4,5,6}, {10, 8, -12}};
for (int row = 0 ; row<rowNum; row++){
for(int col = 0; col<rowNum; col++){
val = sc.nextInt();
// val = matrix[row][col];
if(row == col){
left += val;
}
if(col == rowNum - (1 + row)){
right += val;
}
}
}
System.out.println (Math.abs(left - right));
}
}