![JAR search and dependency download from the Maven repository](/logo.png)
g1701_1800.s1727_largest_submatrix_with_rearrangements.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 g1701_1800.s1727_largest_submatrix_with_rearrangements
// #Medium #Array #Sorting #Greedy #Matrix #2023_06_16_Time_650_ms_(100.00%)_Space_83.9_MB_(100.00%)
class Solution {
fun largestSubmatrix(matrix: Array): Int {
val m: Int = matrix.size
val n: Int = matrix[0].size
for (i in 1 until m) {
for (j in 0 until n) {
if (matrix[i][j] != 0) {
matrix[i][j] = matrix[i - 1][j] + 1
}
}
}
var count = 0
for (ints: IntArray in matrix) {
ints.sort()
for (j in 1..n) {
count = Math.max(count, j * ints[n - j])
}
}
return count
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy