当前位置:网站首页>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 .
边栏推荐
- Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
- Slider verification code identification gadget display
- JS how to convert a string with a delimiter into an n-dimensional array
- Blue Bridge Cup real topic: the shortest circuit
- PCL learning materials
- [source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
- Definition of rotation axis in mujoco
- MFC obtains local IP (used more in network communication)
- Relationship between sensor size, pixel, dpi resolution, inch and millimeter
- APK签名流程介绍[通俗易懂]
猜你喜欢

Static timing analysis (STA) in ic/fpga design

Database - MySQL advanced SQL statement (I)

Penetration practice vulnhub range Tornado

Extract the compressed package file and retrieve the password

Sum of three numbers

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"

Review Net 20th anniversary development and 51aspx growth

Length of learning and changing

Record 3 - the state machine realizes key control and measures the number of external pulses

A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database
随机推荐
[2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
Redis master-slave realizes 10 second check and recovery
MySQL + JSON = King fried
因子分析怎么计算权重?
Smart factory digital management system software platform
L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
Single element of an ordered array
Apk signature process introduction [easy to understand]
540. Single element in ordered array
ArrayList扩容详解
Terms related to K line
The latest software scheme of the intelligent information management system of the armed police force
Mujoco model learning record
Equipment simulation and deduction training system software
Session layer of csframework, server and client (1)
Detailed explanation of ArrayList expansion
Rust language - cargo, crates io