We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c4efbc commit 7197798Copy full SHA for 7197798
Python/lucky-numbers-in-a-matrix.py
@@ -0,0 +1,32 @@
1
+# Time: O(m * n)
2
+# Space: O(m + n)
3
+
4
+import itertools
5
6
7
+class Solution(object):
8
+ def luckyNumbers (self, matrix):
9
+ """
10
+ :type matrix: List[List[int]]
11
+ :rtype: List[int]
12
13
+ rows = map(min, matrix)
14
+ cols = map(max, itertools.izip(*matrix))
15
+ return [cell for i, row in enumerate(matrix)
16
+ for j, cell in enumerate(row) if rows[i] == cols[j]]
17
18
19
20
21
22
23
24
+class Solution2(object):
25
26
27
28
29
30
+ return list(set(map(min, matrix)) &
31
+ set(map(max, itertools.izip(*matrix))))
32
0 commit comments