# 样例 1

``````输入：
accounts = [[1,2,3],[3,2,1]]

6

``````

# 样例 2

``````输入：
accounts = [[1,5],[7,3],[3,5]]

10

``````

# 样例 3

``````输入：
accounts = [[2,8,7],[7,1,3],[1,9,5]]

17
``````

# 提示

• m == accounts.length
• n == accounts[i].length
• 1 <= m, n <= 50
• 1 <= accounts[i][j] <= 100

# 分析

• 无论如何都是要双循环了，貌似也不好优化，除了可以搞搞语法糖。

# 题解

## java

``````class Solution {

public int maximumWealth(int[][] accounts) {

return Arrays.stream(accounts).map(ints -> Arrays.stream(ints).sum()).max(Integer::compareTo).get();
}
}
``````

## c

``````int maximumWealth(int** accounts, int accountsSize, int* accountsColSize){

int max = 0;
for (int i = 0; i < accountsSize; ++i) {

int sum = 0;
for (int j = 0; j < accountsColSize[i]; ++j) {

sum += accounts[i][j];
}
if (sum > max) {

max = sum;
}
}
return max;
}
``````

## c++

``````class Solution {

public:
int maximumWealth(vector<vector<int>>& accounts) {

int max = 0;
for (int i = 0; i < accounts.size(); ++i) {

int sum = 0;
for (int j = 0; j < accounts[i].size(); ++j) {

sum += accounts[i][j];
}
if (max < sum) {

max = sum;
}
}
return max;
}
};
``````

## python

``````class Solution:
def maximumWealth(self, accounts: List[List[int]]) -> int:
return max(sum(accounts[i]) for i in range(len(accounts)))
``````

## go

``````func maximumWealth(accounts [][]int) int {

max := 0
for _, columns := range accounts {

sum := 0
for _, column := range columns {

sum += column
}
if sum > max {

max = sum
}
}
return max
}
``````

## rust

``````impl Solution {
pub fn maximum_wealth(accounts: Vec<Vec<i32>>) -> i32 {
accounts.iter().map(|row|{
row.iter().sum()
}).max().unwrap_or_default()
}
}
``````

# 原题传送门：https://leetcode-cn.com/problems/richest-customer-wealth/

https://le-yi.blog.csdn.net/article/details/120827860