Diagonal Difference

  • + 0 comments

    Java 8:

    public static int diagonalDifference(List<List<Integer>> arr) {
    int sum1 = 0;
    int sum2 = 0;
        int j = arr.size() - 1;
        for (int i = 0; i < arr.size(); i++) {
            sum1 += arr.get(i).get(i);
            sum2 += arr.get(i).get(j);
            j--;
        }
        return Math.abs(sum1 - sum2);
    }