当前位置:网站首页>Lucky numbers in the [leetcode daily question] matrix
Lucky numbers in the [leetcode daily question] matrix
2022-07-02 13:06:00 【Oysters bring the sea to Chicago】
The lucky number in the matrix
difficulty : Simple
The minimum value of each line of the record is traversed for the first time , Deposit in set Collection . The second traversal records the maximum value of each column , Deposit in set Collection , When deposit fails , That is, the current element conforms to the rule of lucky number .
The code is as follows :
public List<Integer> luckyNumbers (int[][] matrix) {
List<Integer> res = new ArrayList<>();
Set<Integer> set = new HashSet<>();
int m = matrix.length;
int n = matrix[0].length;
for (int i = 0; i < m; i++) {
int tmp = Integer.MAX_VALUE;
for (int j = 0; j < n; j++) {
tmp = Math.min(tmp,matrix[i][j]);
}
set.add(tmp);
}
for (int i = 0; i < n; i++) {
int tmp = Integer.MIN_VALUE;
for (int j = 0; j < m; j++) {
tmp = Math.max(tmp,matrix[j][i]);
}
if (!set.add(tmp)){
res.add(tmp);
}
}
return res;
}
Execution results : success
边栏推荐
- Linear DP acwing 897 Longest common subsequence
- Mobile layout (flow layout)
- 8 examples of using date commands
- Hash table acwing 840 Simulated hash table
- Variable, "+" sign, data type
- Jerry's weather code table [chapter]
- How to get the operating system running PHP- How to get the OS on which PHP is running?
- Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
- Jerry's weather code table [chapter]
- C operator
猜你喜欢
难忘阿里,4面技术5面HR附加笔试面,走的真艰难真心酸
Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
Jerry's watch gets the default ringtone selection list [article]
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
JDBC prevent SQL injection problems and solutions [preparedstatement]
Linear DP acwing 898 Number triangle
嵌入式软件开发
Mobile layout (flow layout)
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
上海交大教授:何援军——包围盒(包容体/包围盒子)
随机推荐
JDBC prevent SQL injection problems and solutions [preparedstatement]
Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
Js3day (array operation, JS bubble sort, function, debug window, scope and scope chain, anonymous function, object, Math object)
Redis bloom filter
Jerry's weather code table [chapter]
Efficiency comparison between ArrayList and LinkedList
Typora+docsify quick start
JS iterator generator asynchronous code processing promise+ generator - > await/async
How to get the operating system running PHP- How to get the OS on which PHP is running?
JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
嵌入式软件开发
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
std::vector批量导入快速去重方法
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
Jerry's watch reads the alarm clock [chapter]
Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
上手报告|今天聊聊腾讯目前在用的微服务架构
. Net, C # basic knowledge
完全自主可控三维云CAD:CrownCAD便捷的命令搜索,快速定位所需命令具体位置。