Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 528 Bytes

766.toeplitz-matrix.md

File metadata and controls

23 lines (19 loc) · 528 Bytes

The idea is quite easy, iterate all index and check the value of up-left position.

(i - 1, j - 1)
              \
            (i, j)
fun isToeplitzMatrix(matrix: Array<IntArray>): Boolean {
    val m = matrix.size
    val n = matrix[0].size

    for (i in 0 until m) {
        for (j in 0 until n) {
            if (i - 1 >= 0 && j - 1 >= 0 && matrix[i - 1][j - 1] != matrix[i][j]) return false
        }
    }
    return true
}