Description
Given a m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order. A lucky number is an element that is minimum in its row and maximum in its column.
Examples
Input:
matrix = [[3,7,8],[9,11,13],[15,16,17]]Output:
[15]Explanation:
15 is min in row and max in column.
Input:
matrix = [[7,8],[1,2]]Output:
[7]Explanation:
7 is the minimum in its row [7,8] and also the maximum in its column [7,1]. The number 1 is minimum in row [1,2] but not maximum in column [7,1]. The number 2 is maximum in column [8,2] but not minimum in its row.
Input:
matrix = [[1,2,3,4,5]]Output:
[1,2,3,4,5]Explanation:
In a single row matrix, every element is both the minimum of its row and the maximum of its column (since each column has only one element). Therefore, all elements [1,2,3,4,5] are lucky numbers.
Constraints
- •
1 ≤ m, n ≤ 50