package leetcode;

/**
 * https://leetcode.com/problems/matrix-diagonal-sum/
 */
public class Problem1572 {
    public int diagonalSum(int[][] mat) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1572 prob = new Problem1572();
        System.out.println(prob.diagonalSum(new int[][]{
            {1,2,3},
            {4,5,6},
            {7,8,9}
        })); // 25
        System.out.println(prob.diagonalSum(new int[][]{
            {1,1,1,1},
            {1,1,1,1},
            {1,1,1,1},
            {1,1,1,1},
        })); // 7
        System.out.println(prob.diagonalSum(new int[][]{
            {5},
        })); // 5
    }
}

@@ -155,38 +155,28 @@
     
-// TODO%0A        return
+int answer =
  0;%0A    
 %7D%0A%0A 
@@ -175,296 +175,177 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1572 prob = new Problem1572();%0A        System.out.println(prob.diagonalSum(new int%5B%5D%5B%5D%7B%0A            %7B1,2,3%7D,%0A            %7B4,5,6%7D,%0A            %7B7,8,9%7D%0A        %7D)); // 25%0A        System.out.println(prob.diagonalSum(new in
+int maxRow = mat.length;%0A        int maxCol = maxRow %3E 0 ? mat%5B0%5D.length : 0;%0A        for (int i = 0, j = 0; i %3C maxRow; i++, j++) %7B%0A            answer += ma
 t%5B
+i
 %5D%5B
-%5D%7B
+j%5D;
 %0A   
@@ -353,201 +353,196 @@
     
-    %7B1,1,1,1%7D,%0A            %7B1,1,1,1%7D,%0A            %7B1,1,1,1%7D,%0A            %7B1,1,1,1%7D,%0A        %7D)); // 7%0A        System.out.println(prob.diagonalSum(new int%5B%5D%5B%5D%7B%0A            %7B5%7D,%0A        %7D)); // 5
+%7D%0A        for (int i = 0, j = maxCol - 1; i %3C maxRow; i++, j--) %7B%0A            answer += mat%5Bi%5D%5Bj%5D;%0A        %7D%0A        return maxRow %25 2 == 0 ? answer : answer - mat%5BmaxRow / 2%5D%5BmaxRow / 2%5D;
 %0A   

Solve problem 1572