Matej Focko
8e196a299a
URL: https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows/ Signed-off-by: Matej Focko <me@mfocko.xyz>
18 lines
475 B
Kotlin
18 lines
475 B
Kotlin
class Solution {
|
|
fun maxEqualRowsAfterFlips(matrix: Array<IntArray>): Int {
|
|
val freqs = mutableMapOf<String, Int>()
|
|
|
|
matrix
|
|
.map { row ->
|
|
row.map { it == row[0] }.joinToString(separator = "")
|
|
}
|
|
.forEach { pattern ->
|
|
freqs.put(
|
|
pattern,
|
|
1 + freqs.getOrDefault(pattern, 0),
|
|
)
|
|
}
|
|
|
|
return freqs.values.max()
|
|
}
|
|
}
|