当前位置:网站首页>2022.02.15 - 240. Lucky number in matrix
2022.02.15 - 240. Lucky number in matrix
2022-06-29 06:16:00 【A CAI continues to work hard】
List of articles
1. subject


2. Ideas
(1) Simulation
- ergodic matrix , Find out the minimum value of each row first , Find out the maximum value of each column , If there are duplicate elements , Indicates that the element is a lucky number .
3. Code
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Test {
public static void main(String[] args) {
}
}
class Solution {
public List<Integer> luckyNumbers(int[][] matrix) {
int m = matrix.length;
int n = matrix[0].length;
List<Integer> res = new ArrayList<>();
Set<Integer> set = new HashSet<>();
for (int i = 0; i < m; i++) {
int min = Integer.MAX_VALUE;
for (int j = 0; j < n; j++) {
min = Math.min(min, matrix[i][j]);
}
set.add(min);
}
for (int i = 0; i < n; i++) {
int max = Integer.MIN_VALUE;
for (int j = 0; j < m; j++) {
max = Math.max(max, matrix[j][i]);
}
if (!set.add(max)) {
res.add(max);
}
}
return res;
}
}
边栏推荐
- How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
- Why Houdini made the pyside2 plug-in crash
- Installing modules in pycharm
- Rich material libraries make modeling easy and efficient for developers
- Activiti Designer
- The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers
- About: deleting unwanted event log lists
- Devops development, operation and maintenance Basics: using Jenkins to automatically build projects and notify by email
- Internet enterprises need CRM software to help
- Why can't the article be posted?
猜你喜欢

What is the "danksharding" of V God Kop on Valentine's day?

Quickly write MVVM code using source generators

Meta metauniverse female safety problems occur frequently. How to solve the relevant problems in the metauniverse?

Internet enterprises need CRM software to help

2-nitro-5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin (no2tdmpp) H2) /5,10,15,20-tetra (4-methylphenyl) porphyrin (TMPP) H2) Qiyue porphyrin products

National Defense University project summary

Why Houdini made the pyside2 plug-in crash

2,5-di (3,4-dicarboxyphenoxy) - 4 '- phenylethynylbiphenyldianhydride (pephqda) / Qiyue custom supply porphyrin modified amphiphilic block copolymer peg113-pcl46-porphyrin

Creation of Arduino uno development environment

Pytest (7) -yield and termination function
随机推荐
Mongodb paging method
Activiti Designer
Fault: display Storport driver out of date in component health
Longest substring between two identical characters of leetcode simple question
Difference between URI and URL
Servlet version conflict causes page 404
Hyperledger Fabric 2. X custom smart contract
How to use regex in file find
What are the uses of static?
Regular expressions for shell script values
3 frequently tested SQL data analysis questions (including data and code)
Analysis report on the investment market situation of the development planning prospect of the recommended chip industry research industry in 2022 (the attachment is a link to the network disk, and th
JIRA basic usage sharing
Leetcode notes on question brushing (XIV) -- related topics of binary tree attributes in binary tree chapter
Research Report on recommended specialized, special and new industries in 2022 industry development prospect and market investment analysis (the attachment is a link to the online disk, and the report
Design and practice of kubernetes cluster and application monitoring scheme
Fault: NetBt log for id4321
Jenkins operation Chapter 5 trigger, configuration webhook, Jenkins parameterized construction
2022 recommended RCEP regional comprehensive economic partnership agreement market quotation Investment Analysis Industry Research Report (the attachment is a link to the online disk, and the report i
Rich material libraries make modeling easy and efficient for developers