![JAR search and dependency download from the Maven repository](/logo.png)
g2901_3000.s2946_matrix_similarity_after_cyclic_shifts.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
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