当前位置:网站首页>LeetCode:1380. Lucky number in matrix -- simple
LeetCode:1380. Lucky number in matrix -- simple
2022-07-02 17:17:00 【Kinght_ one hundred and twenty-three】
subject
1380. The lucky number in the matrix
To give you one m * n Matrix , The number in the matrix Each are not identical . Please press arbitrarily Return all the lucky numbers in the matrix in order .
Lucky number refers to the elements in the matrix that meet the following two conditions at the same time :
- The smallest of all elements in the same row
- The largest of all elements in the same column
Example 1:
Input :matrix = [[3,7,8],[9,11,13],[15,16,17]]
Output :[15]
explain :15 Is the only lucky number , Because it is the smallest value in its row , It is also the maximum value in the column .
Example 2:
Input :matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
Output :[12]
explain :12 Is the only lucky number , Because it is the smallest value in its row , It is also the maximum value in the column .
Example 3:
Input :matrix = [[7,8],[1,2]]
Output :[7]
Tips :
- m == mat.length
- n == mat[i].length
- 1 <= n, m <= 50
- 1 <= matrix[i][j] <= 10^5
- All elements in the matrix are different
Their thinking
- simulation .
Code
class Solution:
def luckyNumbers (self, matrix: List[List[int]]) -> List[int]:
ans = []
for nums in matrix:
for i in range(len(nums)):
if nums[i] == min(nums) and nums[i] == max(sit[i] for sit in matrix):
ans.append(nums[i])
return ans
Running results
边栏推荐
- Eth data set download and related problems
- ThreadLocal
- What is generics- Introduction to generics
- lsf基础命令
- 智能垃圾桶(五)——点亮OLED
- 剑指 Offer 24. 反转链表
- 伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
- Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion
- Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights
- Use of openpose
猜你喜欢
PhD battle-11 preview | review and prospect backdoor attack and defense of neural network
七张图,学会做有价值的经营分析
linux安装postgresql + patroni 集群问题
【Leetcode】14. 最長公共前綴
Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements
Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion
Sword finger offer 27 Image of binary tree
A few lines of code to complete RPC service registration and discovery
Sword finger offer 22 The penultimate node in the linked list
上传代码到远程仓库报错error: remote origin already exists.
随机推荐
【Leetcode】14. 最長公共前綴
Linux Installation PostgreSQL + Patroni cluster problem
The macrogenome microbiome knowledge you want is all here (2022.7)
你想要的宏基因组-微生物组知识全在这(2022.7)
对接保时捷及3PL EDI案例
Sword finger offer 24 Reverse linked list
Tech talk activity preview | building intelligent visual products based on Amazon kVs
Usage of sprintf() function in C language
The impact of telecommuting on all aspects of our experience | community essay solicitation
ThreadLocal
Domestic relatively good OJ platform [easy to understand]
福元医药上交所上市:市值105亿 胡柏藩身价超40亿
伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
Blog theme "text" summer fresh Special Edition
Use the API port of the bridge of knowledge and action to provide resources for partners to access
ssb门限_SSB调制「建议收藏」
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
linux下配置Mysql授权某个用户远程访问,不受ip限制
Youzan won the "top 50 Chinese enterprise cloud technology service providers" together with Tencent cloud and Alibaba cloud [easy to understand]
Geoserver: publishing PostGIS data sources