All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g2901_3000.s2946_matrix_similarity_after_cyclic_shifts.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.32
Show newest version
package g2901_3000.s2946_matrix_similarity_after_cyclic_shifts

// #Easy #Array #Math #Matrix #Simulation #2023_12_31_Time_210_ms_(75.00%)_Space_44_MB_(36.54%)

@Suppress("NAME_SHADOWING")
class Solution {
    fun areSimilar(mat: Array, k: Int): Boolean {
        var k = k
        val m = mat.size
        val n = mat[0].size
        k %= n
        for (i in 0 until m) {
            for (j in 0 until n) {
                if ((i and 1) != 0) {
                    if (mat[i][j] != mat[i][(j - k + n) % n]) {
                        return false
                    }
                } else {
                    if (mat[i][j] != mat[i][(j + k) % n]) {
                        return false
                    }
                }
            }
        }
        return true
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy