当前位置:网站首页>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

边栏推荐
猜你喜欢

The computer comes with software to make the background color of the picture transparent (matting white background)

Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品

宝宝巴士创业板IPO被终止:曾拟募资18亿 唐光宇控制47%股权

伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO

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
![[leetcode] 14. Préfixe public le plus long](/img/70/e5be1a7c2e10776a040bfc8d7711a0.png)
[leetcode] 14. Préfixe public le plus long

A few lines of code to complete RPC service registration and discovery

博客主题 “Text“ 夏日清新特别版

DGraph: 大规模动态图数据集

Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
随机推荐
&lt;四&gt; H264解码输出yuv文件
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia
TCP拥塞控制详解 | 2. 背景
如何与博格华纳BorgWarner通过EDI传输业务数据?
七张图,学会做有价值的经营分析
人生的开始
871. Minimum refueling times
远程办公对我们的各方面影响心得 | 社区征文
剑指 Offer 25. 合并两个排序的链表
Sword finger offer 24 Reverse linked list
关于举办科技期刊青年编辑沙龙——新时代青年编辑应具备的能力及提升策略的通知...
The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?
Sword finger offer 26 Substructure of tree
亚马逊云科技 Community Builder 申请窗口开启
The impact of telecommuting on all aspects of our experience | community essay solicitation
R及RStudio下载安装教程(超详细)
相信自己,这次一把搞定JVM面试
Exploration of mobile application performance tools
871. 最低加油次数