From 8547278853d076db29b7b6353078a235d1c243f5 Mon Sep 17 00:00:00 2001 From: eat-swap Date: Thu, 14 Apr 2022 20:19:47 +0800 Subject: [PATCH] add: 220414-CN (3) [cpp] --- cpp/2204/220414-CN.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/2204/220414-CN.cpp b/cpp/2204/220414-CN.cpp index deeecc6..ac0f438 100644 --- a/cpp/2204/220414-CN.cpp +++ b/cpp/2204/220414-CN.cpp @@ -14,8 +14,8 @@ class Solution { public: static int maximumWealth(const std::vector>& accounts) { - std::vector tmp; - std::for_each(accounts.cbegin(), accounts.cend(), [&](const std::vector& x) { tmp.push_back(std::accumulate(x.cbegin(), x.cend(), 0)); }); - return *std::max_element(tmp.cbegin(), tmp.cend()); + int ret = 0; + std::for_each(accounts.cbegin(), accounts.cend(), [&](const std::vector& x) { ret = std::max(ret, std::accumulate(x.cbegin(), x.cend(), 0)); }); + return ret; } };