链接
https://leetcode-cn.com/problems/richest-customer-wealth/
耗时
解题:5 min
题解:6 min
题意
给你一个 m x n 的整数网格 accounts ,其中 accounts[i][j] 是第 i 位客户在第 j 家银行托管的资产数量。返回最富有客户所拥有的 资产总量 。
客户的 资产总量 就是他们在各家银行托管的资产数量之和。最富有客户就是 资产总量 最大的客户。
思路
返回 accounts 每行的和的最大值。详见代码。
时间复杂度:
O
(
m
∗
n
)
O(m*n)
O(m∗n)
AC代码
class Solution {
public:
int maximumWealth(vector<vector<int>>& accounts) {
int ans = 1;
for(auto acci : accounts) {
ans = max(ans, accumulate(acci.begin(), acci.end(), 0));
}
return ans;
}
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)