Leetcode 1496 Solution
This article provides solution to leetcode question 1496 (lucky-numbers-in-a-matrix)
Access this page by simply typing in "lcs 1496" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/lucky-numbers-in-a-matrix
Solution
class Solution:
def luckyNumbers (self, matrix: List[List[int]]) -> List[int]:
m = len(matrix)
n = len(matrix[0])
row_mins = [min(values) for values in matrix]
col_mins = []
for j in range(n):
values = []
for i in range(m):
values.append(matrix[i][j])
col_mins.append(max(values))
ans = []
for i in range(m):
for j in range(n):
if matrix[i][j] == row_mins[i] == col_mins[j]:
ans.append(matrix[i][j])
return ans