mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-24 02:14:00 +08:00
28 lines
459 B
Go
28 lines
459 B
Go
package leetcode
|
|
|
|
func luckyNumbers(matrix [][]int) []int {
|
|
t, r, res := make([]int, len(matrix[0])), make([]int, len(matrix[0])), []int{}
|
|
for _, val := range matrix {
|
|
m, k := val[0], 0
|
|
for j := 0; j < len(matrix[0]); j++ {
|
|
if val[j] < m {
|
|
m = val[j]
|
|
k = j
|
|
}
|
|
if t[j] < val[j] {
|
|
t[j] = val[j]
|
|
}
|
|
}
|
|
|
|
if t[k] == m {
|
|
r[k] = m
|
|
}
|
|
}
|
|
for k, v := range r {
|
|
if v > 0 && v == t[k] {
|
|
res = append(res, v)
|
|
}
|
|
}
|
|
return res
|
|
}
|