当前位置:网站首页>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 .
边栏推荐
- When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
- Convert the robot's URDF file to mujoco model
- Cloud computing - make learning easier
- Redis主从实现10秒检查与恢复
- Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
- Nielseniq found that 60% of the re launched products had poor returns
- Distributed task queue: Celery usage record
- [2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
- [source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
- Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
猜你喜欢

因子分析怎么计算权重?

主成分之综合竞争力案例分析

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

Basic concepts of binary tree

12种数据量纲化处理方式

Classpath classpath

transform. Forward and vector3 Differences in the use of forward
![[PHP foundation] realize the connection between PHP and SQL database](/img/eb/c8953eddfe3b19b0adb5529957d275.jpg)
[PHP foundation] realize the connection between PHP and SQL database
![[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out](/img/f3/20b73f3545cdd17b9fbc52bf493ab4.jpg)
[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out

The method of real-time tracking the current price of London Silver
随机推荐
Is Alipay wallet convenient to use?
Zabbix报警执行远程命令
t10_ Adapting to Market Participantsand Conditions
12种数据量纲化处理方式
Software construction scheme of smart factory collaborative management and control application system
Operation of cmake under win
The method of real-time tracking the current price of London Silver
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl
ArrayList扩容详解
12. Design of power divider for ads usage record
LeetCode 148. Sort linked list
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Domestic spot silver should be understood
Terms related to K line
Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
主成分计算权重
Sanfeng cloud 0215 I often use
Blue Bridge Cup real question: score statistics
Oracle TRUNC function processing date format