package leetcode;

/**
 * https://leetcode.com/problems/toeplitz-matrix/
 */
public class Problem766 {
    public boolean isToeplitzMatrix(int[][] matrix) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem766 prob = new Problem766();
        System.out.println(prob.isToeplitzMatrix(new int[][]{
            {1, 2, 3, 4},
            {5, 1, 2, 3},
            {9, 5, 1, 2}
        })); // true
        System.out.println(prob.isToeplitzMatrix(new int[][]{
            {1, 2},
            {2, 2}
        })); // false
    }
}

@@ -162,375 +162,1020 @@
     
-// TODO%0A        return false;%0A
+int numRows = matrix.length;%0A        int numCols = 0;%0A        if (matrix.length %3E 0) %7B%0A            numCols = matrix%5B0%5D.length;%0A   
     
+ 
 %7D
-%0A
 %0A    
-public static void main(String%5B%5D args) %7B%0A        Problem766 prob = new Problem766();%0A        System.out.println(prob.isToeplitzMatrix(new int%5B%5D%5B%5D%7B%0A            %7B1, 2, 3, 4%7D,%0A            %7B5, 1, 2, 3%7D,%0A            %7B9, 5, 1, 2%7D%0A        %7D)); //
+    boolean same = isSameDiagonal(matrix, 0, 0, numRows, numCols);%0A        if (!same) %7B%0A            return false;%0A        %7D%0A        for (int col = 1; col %3C numCols; col++) %7B%0A            if (!isSameDiagonal(matrix, 0, col, numRows, numCols)) %7B%0A                return false;%0A            %7D%0A        %7D%0A        for (int row = 1; row %3C numRows; row++) %7B%0A            if (!isSameDiagonal(matrix, row, 0, numRows, numCols)) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return
  true
+;
 %0A    
+%7D%0A%0A
     
-System.out.println(prob.isToeplitzMatrix(new int%5B%5D%5B%5D%7B%0A            %7B1, 2%7D,
+private static boolean isSameDiagonal(int%5B%5D%5B%5D matrix, int row, int col, int numRows, int numCols) %7B%0A        int a = -1;%0A        for (int r = row, c = col; r %3C numRows && c %3C numCols; r++, c++) %7B%0A            if (a == -1) %7B%0A                a = matrix%5Br%5D%5Bc%5D;%0A            %7D else %7B%0A                if (matrix%5Br%5D%5Bc%5D != a) %7B%0A                    return false;%0A                %7D
 %0A   
@@ -1187,13 +1187,8 @@
     
-%7B2, 2
 %7D%0A  
@@ -1198,20 +1198,29 @@
    %7D
-)); // false
+%0A        return true;
 %0A   

Solve problem 766