-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJul-19-24.py
36 lines (36 loc) · 1.14 KB
/
Jul-19-24.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution:
def __init__(self):
self.rows = defaultdict(list)
self.cols = defaultdict(list)
def luckyNumbers (self, mat: List[List[int]]) -> List[int]:
def minRow(arr):
miN,idx = float('inf'),-1
for i,x in enumerate(arr):
if miN>x:
miN = x
idx = i
return (miN,idx)
def maxCol(mat,col):
i = 0
maX,idx = float('-inf'),-1
while i<len(mat):
if maX<mat[i][col]:
maX = mat[i][col]
idx = col
i += 1
return (maX,idx)
for row in mat:
val,idx = minRow(row)
self.rows[idx].append(val)
for i in range(len(mat[0])):
val,idx = maxCol(mat,i)
self.cols[idx].append(val)
res = []
for i in range(max(len(mat),len(mat[0]))):
rowSet = set()
for j in self.rows[i]:
rowSet.add(j)
for j in self.cols[i]:
if j in rowSet:
res.append(j)
return res