当前位置:网站首页>1380. Lucky number in matrix / 1672 Total assets of the richest customers
1380. Lucky number in matrix / 1672 Total assets of the richest customers
2022-07-01 18:35:00 【PI Qiliang】
1380. The lucky number in the matrix 【 Simple questions 】【 A daily topic 】
Ideas :
- First find the minimum value of each line , Deposited in the collection list_r in , Set subscript corresponds to line number ; Then find out the maximum value of each column , Deposited in the collection list_c in , Set subscript corresponds to column number .
- Traverse every element of the matrix , Use common for loop , Judge whether the current element is the minimum value of the current row and the maximum value of the current column , If both , Then add the current element to the collection ans in .
- Finally back to ans that will do .
Code :
class Solution {
public List<Integer> luckyNumbers (int[][] matrix) {
List<Integer> ans = new ArrayList<>();
List<Integer> list_r = new ArrayList<>();
List<Integer> list_c = new ArrayList<>();
for (int[] row : matrix) {
int min = Integer.MAX_VALUE;
for (int col : row){
min = Math.min(min,col);
}
list_r.add(min);
}
for (int i = 0; i < matrix[0].length; i++) {
int max = 0;
for (int[] row : matrix) {
max = Math.max(max, row[i]);
}
list_c.add(max);
}
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
int cur = matrix[i][j];
if (cur == list_r.get(i) && cur == list_c.get(j)){
ans.add(cur);
}
}
}
return ans;
}
}
when :
3ms, beat 55.52%.
1672. Total assets of the richest clients 【 Simple questions 】
- Define a int Type variable max Indicates the total assets of the richest customers .
- Traverse every customer , Calculate its total assets sum, take max Updated to max and sum The maximum of .
- After all customers are traversed, the current maximum value is returned max That is, the total assets of the richest customers .
Code :
class Solution {
public int maximumWealth(int[][] accounts) {
int max = 0;
for (int[] costumer : accounts){
int sum = 0;
for (int money : costumer){
sum += money;
}
max = Math.max(max,sum);
}
return max;
}
}
when :
There is no official solution to this problem at present .
边栏推荐
- Cassette helicopter and alternating electric field magnetic manometer DPC
- What are the six steps of the software development process? How to draw software development flow chart?
- 主成分计算权重
- Sum of three numbers
- From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl
- Slider verification code identification gadget display
- [image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
- [PHP foundation] realize the connection between PHP and SQL database
- The ultimate version of the 13th simulation of the single chip microcomputer provincial competition of the Blue Bridge Cup
- 網上股票開戶安全嗎?是否可靠?
猜你喜欢
How to retrieve the password for opening Excel files
Cassette helicopter and alternating electric field magnetic manometer DPC
Localization through custom services in the shuttle application
Set the style of QT property sheet control
Yuancosmos game farmersworld farmers world - core content of the second conference in China!
An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
必看,时间序列分析
信度系数低怎么办?信度系数具体怎么算?
Mysql database design
随机推荐
Nielseniq found that 60% of the re launched products had poor returns
Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
聊聊项目经理最爱使用的工具
Mujoco model learning record
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
Blue Bridge Cup real question: score statistics
Common design parameters of solid rocket motor
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Vue uses keep alive to cache page optimization projects
SCP -i private key usage
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
D. Yet Another Minimization Problem
Mujoco XML modeling
主成分计算权重
12. Design of power divider for ads usage record
12种数据量纲化处理方式
Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
Fix the problem that easycvr device video cannot be played
Penetration practice vulnhub range Tornado
Sanfeng cloud 0215 I often use