其他分享
首页 > 其他分享> > 766. Toeplitz Matrix

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;

    }

 

标签:return,matrix,int,766,++,length,Toeplitz,true,Matrix
来源: https://www.cnblogs.com/feiflytech/p/15860298.html