当前位置:网站首页>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 .
边栏推荐
- Is Alipay wallet convenient to use?
- 网上股票开户安全吗?是否可靠?
- [image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
- Blackwich: the roadmap of decarbonization is the first step to realize the equitable energy transformation in Asia
- Apk signature process introduction [easy to understand]
- Classpath classpath
- Fix the black screen caused by iPhone system failure
- Data query language (DQL)
- The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup
- Mujoco XML modeling
猜你喜欢
C# SelfHost WebAPI (2)
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Mysql database design
Depth first search - DFS (burst search)
Localization through custom services in the shuttle application
Mujoco XML modeling
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
MySQL connection tools
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Search 2D matrix 2
随机推荐
12种数据量纲化处理方式
主成分计算权重
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
The method of real-time tracking the current price of London Silver
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Smart factory digital management system software platform
Three dimensional anti-terrorism Simulation Drill deduction training system software
C operator overloads the query table
A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database
PIP version problems: PIP problems still occur when installing akshare and using Tsinghua source and Douban source
Step size of ode45 and reltol abstol
Computer network interview assault
Blackwich: the roadmap of decarbonization is the first step to realize the equitable energy transformation in Asia
Basic concepts of binary tree
信度系数低怎么办?信度系数具体怎么算?
Bernoulli distribution (a discrete distribution)
Function, condition, regular expression
Session layer of csframework, server and client (1)
What impact will multinational encryption regulation bring to the market in 2022
The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup