题目地址:
https://leetcode.com/problems/richest-customer-wealth/
给定一个二维数组 A A A, A [ i ] A[i] A[i]代表客户 i i i在各个银行的资产。问总资产最多的客户的总资产是多少。
直接统计。代码如下:
public class Solution {
public int maximumWealth(int[][] accounts) {
int res = 0;
for (int[] account : accounts) {
int asset = 0;
for (int i = 0; i < account.length; i++) {
asset += account[i];
}
res = Math.max(res, asset);
}
return res;
}
}
时间复杂度 O ( m n ) O(mn) O(mn), m m m是 A A A的行数, n n n是 A A A的列数,空间 O ( 1 ) O(1) O(1)。