766. Toeplitz Matrix

Don't think about a lot, this is a very easy problem, time complexity is O(m*n)

    public boolean isToeplitzMatrix(int[][] matrix) {
        if (matrix == null || matrix[0].length == 0)
            return true;
        int m = matrix.length, n = matrix[0].length;
        for (int i = 0; i < m - 1; i++) {
            for (int j = 0; j < n - 1; j++) {
                if (matrix[i][j] != matrix[i + 1][j + 1])
                    return false;
            }
        }
        return true;

    }

Or the similar one:

    public boolean isToeplitzMatrix(int[][] matrix) {
        if (matrix == null || matrix[0].length == 0)
            return true;
        int m = matrix.length, n = matrix[0].length;
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                if (matrix[i][j] != matrix[i - 1][j - 1])
                    return false;
            }
        }
        return true;

    }

 

上一篇:Java中的StringUtils引入及使用


下一篇:pytorch学习笔记二之自动差分引擎