kt: add «1072. Flip Columns For Maximum Number of Equal Rows»
URL: https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
2e21177633
commit
8e196a299a
1 changed files with 18 additions and 0 deletions
18
kt/flip-columns-for-maximum-number-of-equal-rows.kt
Normal file
18
kt/flip-columns-for-maximum-number-of-equal-rows.kt
Normal file
|
@ -0,0 +1,18 @@
|
|||
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()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue