g1301_1400.s1380_lucky_numbers_in_a_matrix.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 g1301_1400.s1380_lucky_numbers_in_a_matrix
// #Easy #Array #Matrix #2023_06_06_Time_223_ms_(89.29%)_Space_37.9_MB_(85.71%)
class Solution {
fun luckyNumbers(matrix: Array): List {
val mini: MutableList = ArrayList()
val maxi: MutableList = ArrayList()
for (arr in matrix) {
var min = Int.MAX_VALUE
for (j in arr) {
if (min > j) {
min = j
}
}
mini.add(min)
}
val cols = matrix[0].size
for (c in 0 until cols) {
var max = Int.MIN_VALUE
for (ints in matrix) {
if (ints[c] > max) {
max = ints[c]
}
}
maxi.add(max)
}
val res: MutableList = ArrayList()
for (value in mini) {
if (maxi.contains(value)) {
res.add(value)
}
}
return res
}
}