Toeplitz Matrix

查一个matrix是不是左上到右下的元素都一样.

class Solution {
    public boolean isToeplitzMatrix(int[][] matrix) {
        boolean res = true;
        for(int i = 0; i < matrix.length; i++) {
            res &= check(matrix, i, 0, matrix[i][0]);
        }
        for(int i = 0; i < matrix[0].length; i++) {
            res &= check(matrix, 0, i, matrix[0][i]);
        }
        return res;
    }
    
    public boolean check(int[][] m, int i, int j, int v) {
        if(i < 0 || i >= m.length || j < 0 || j >= m[0].length)
            return true;
        if(m[i][j] != v)
            return false;
        return check(m,i+1,j+1,v);
    }
}