最富有客户的资产总量:
给你一个 m x n 的整数网格 accounts ,其中 accounts[i][j] 是第 i 位客户在第 j 家银行托管的资产数量。返回最富有客户所拥有的 资产总量 。
客户的 资产总量 就是他们在各家银行托管的资产数量之和。最富有客户就是 资产总量 最大的客户。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/richest-customer-wealth
输入:accounts = [[1,5],[7,3],[3,5]]
输出:10
解释:
第 1 位客户的资产总量 = 6
第 2 位客户的资产总量 = 10
第 3 位客户的资产总量 = 8
第 2 位客户是最富有的,资产总量是 10
public class MaximumWealth {
public static int maximumWealth(int[][] accounts) {
int res = 0;
int x = accounts.length;
if (x == 0){
return res;
}
for (int i = 0; i < x; i++) {
int y = accounts[i].length;
if (y == 0){
continue;
}
int sum = 0;
for (int j = 0; j < y; j++) {
sum += accounts[i][j];
}
if (res <= sum){
res = sum;
}
}
return res;
}
public static void main(String[] args) {
int[][] accounts = {{1,2,3},{3,2,1}};
System.out.printf(""+ maximumWealth(accounts));
}
}