We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Diagonal Difference
- Discussions
Diagonal Difference
Diagonal Difference
Sort by
recency
|
648 Discussions
|
Please Login in order to post a comment
no need to two variables to calculate result. In Java public static int diagonalDifference(List> arr) { int n = arr.size(); int result =0; for (int i = 0; i < n; i++) { result += arr.get(i).get(i) - arr.get( i).get(n - i -1); } return Math.abs(result); }
in C
Draw a 3x3 matrix with a pen and paper, and mark out the corrdinates for each diagonal. Will make it clearer.
I had a slightly nuanced approach to what most people did, thought I'd share. Python
Java 8: