From 6669e03a5ea751aacb75c27b17742d8bfc2afc39 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Fri, 19 Jul 2024 13:35:56 +0900 Subject: [PATCH] https://leetcode.com/problems/lucky-numbers-in-a-matrix --- easy/lucky_numbers_in_a_matrix.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 easy/lucky_numbers_in_a_matrix.py diff --git a/easy/lucky_numbers_in_a_matrix.py b/easy/lucky_numbers_in_a_matrix.py new file mode 100644 index 0000000..4c5bd11 --- /dev/null +++ b/easy/lucky_numbers_in_a_matrix.py @@ -0,0 +1,15 @@ +# https://leetcode.com/problems/lucky-numbers-in-a-matrix +from typing import List + +class Solution: + def luckyNumbers (self, matrix: List[List[int]]) -> List[int]: + ret: List[int] = [] + cols: List[int] = list(map(max, zip(*matrix))) + i = 0 + while i < len(matrix): + min_index, min_value = min(enumerate(matrix[i]), key=lambda x: x[1]) + if cols[min_index] == min_value: + ret.append(min_value) + i += 1 + return ret +