LeetCode 1672. Richest Customer Wealth
考点 | 难度 |
---|---|
Matrix | Easy |
题目
You are given an m x n integer grid accounts where accounts[i][j]
is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has.
A customer’s wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum wealth.
思路
算每一行的总和,和当前最大值比较,保留更大的值。
答案
public int maximumWealth(int[][] accounts) {
int res = 0;
for(int i =0;i<accounts.length;i++){
int temp = 0;
for(int j = 0;j<accounts[i].length;j++){
temp+=accounts[i][j];
}
res = Math.max(res,temp);
}
return res;
}