当前位置:网站首页>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 .
边栏推荐
- Session layer of csframework, server and client (1)
- 期货账户的资金安全吗?怎么开户?
- . Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
- The method of real-time tracking the current price of London Silver
- Blue Bridge Cup real topic: the shortest circuit
- Talk about the favorite tools used by project managers
- 网上股票开户安全吗?是否可靠?
- Single element of an ordered array
- Step size of ode45 and reltol abstol
- Detailed explanation of select in golang
猜你喜欢
![[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)](/img/92/f3a70e7086aeedf41eea3eef98b5aa.jpg)
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)

Samba basic usage

Calculation of intersection of two line segments

Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)

. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes

MySQL connection tools

Product service, operation characteristics

Review Net 20th anniversary development and 51aspx growth

Force buckle day33

A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database
随机推荐
聊聊项目经理最爱使用的工具
Fix the problem that easycvr device video cannot be played
540. Single element in ordered array
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
[noip2015] jumping stone
Basic concepts of binary tree
Batch export all pictures in PPT in one second
Fix the black screen caused by iPhone system failure
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
What impact will multinational encryption regulation bring to the market in 2022
Zabbix报警执行远程命令
Key points on February 15, 2022
Record 3 - the state machine realizes key control and measures the number of external pulses
Penetration practice vulnhub range Nemesis
Localization through custom services in the shuttle application
Pytorch crossentropyloss learning
Penetration practice vulnhub range Keyring
Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #
Set the style of QT property sheet control