1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00

problems(kt): add „2133. Check if Every Row and Column Contains All Numbers“

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-09-09 18:58:35 +02:00
parent 1873ff8016
commit f7ebb9037d
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,13 @@
class Solution {
fun checkValid(matrix: Array<IntArray>): Boolean {
val n = matrix.size
val required = (1..n).toSet()
fun checkDimension(
dimensions: Iterable<Iterable<Int>>
): Boolean = dimensions.all { it.toSet() == required }
return checkDimension(matrix.map(IntArray::toList)) &&
checkDimension((0 until n).map { x -> matrix.map { row -> row[x] }})
}
}