Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Kaggle
- Docker
- hackerrank
- ubuntu
- 파이썬
- programmers
- 백준
- 금융문자분석경진대회
- 프로그래머스 파이썬
- Real or Not? NLP with Disaster Tweets
- 데이콘
- SW Expert Academy
- 프로그래머스
- 맥북
- ChatGPT
- leetcode
- 우분투
- 코로나19
- dacon
- gs25
- Git
- AI 경진대회
- PYTHON
- 더현대서울 맛집
- 자연어처리
- Baekjoon
- 캐치카페
- github
- 편스토랑
- 편스토랑 우승상품
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1380. Lucky Numbers in a Matrix (Python) 본문
728x90
반응형
Given a m * n matrix of distinct numbers, return all lucky numbers in the matrix in any order.
A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column.
Example 1:
Input: matrix = [[3,7,8],[9,11,13],[15,16,17]]
Output: [15]
Explanation: 15 is the only lucky number since it is the minimum in its row and the maximum in its column
Example 2:
Input: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
Output: [12]
Explanation: 12 is the only lucky number since it is the minimum in its row and the maximum in its column.
Example 3:
Input: matrix = [[7,8],[1,2]]
Output: [7]
Constraints:
- m == mat.length
- n == mat[i].length
- 1 <= n, m <= 50
- 1 <= matrix[i][j] <= 10^5.
- All elements in the matrix are distinct.
Solution
class Solution:
def luckyNumbers (self, matrix: List[List[int]]) -> List[int]:
matrix_len = len(matrix[0])
row_len = len(matrix)
for i in range(matrix_len):
temp = []
for j in range(row_len):
temp.append(matrix[j][i])
for k in range(row_len):
if max(temp) == min(matrix[k]):
return [max(temp)]
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 1122. Relative Sort Array (Python) (0) | 2020.11.06 |
---|---|
[leetCode] 1287. Element Appearing More Than 25% In Sorted Array (Python) (0) | 2020.11.05 |
[leetCode] 1351. Count Negative Numbers in a Sorted Matrix (Python) (0) | 2020.11.03 |
[leetCode] 1137. N-th Tribonacci Number (Python) (0) | 2020.11.02 |
[leetCode] 509. Fibonacci Number (Python) (0) | 2020.11.01 |
Comments