add: 220414-CN (2) [cpp]

This commit is contained in:
eat-swap 2022-04-14 20:17:55 +08:00
parent e3c092dbfb
commit 1cdbbcaf73
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
1 changed files with 15 additions and 1 deletions

View File

@ -4,4 +4,18 @@
* 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. * 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.
* *
* Refer: 2201/220131.cpp * Refer: 2201/220131.cpp
* 100% STL implementation this time!
*/ */
#include <vector>
#include <numeric>
#include <algorithm>
class Solution {
public:
static int maximumWealth(const std::vector<std::vector<int>>& accounts) {
std::vector<int> tmp;
std::for_each(accounts.cbegin(), accounts.cend(), [&](const std::vector<int>& x) { tmp.push_back(std::accumulate(x.cbegin(), x.cend(), 0)); });
return *std::max_element(tmp.cbegin(), tmp.cend());
}
};