From b0ddcd80d834ca774686d0d7a34ec8d0c96f2d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BE=D1=80=D0=B5=D0=B2=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Mon, 25 Sep 2023 08:29:12 +0300 Subject: [PATCH] Update Find the Difference --- solutions/find-the-difference/solution.hpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/solutions/find-the-difference/solution.hpp b/solutions/find-the-difference/solution.hpp index ed65f306..9fa81029 100644 --- a/solutions/find-the-difference/solution.hpp +++ b/solutions/find-the-difference/solution.hpp @@ -1,21 +1,12 @@ #pragma once +#include #include -#include class Solution { public: static char findTheDifference(std::string s, std::string t) { - std::unordered_map umap; - for (auto c : s) { - umap[c]++; - } - - for (auto c : t) { - if (!umap[c]--) { - return c; - } - } - return '0'; + return std::accumulate(t.begin(), t.end(), 0) - + std::accumulate(s.begin(), s.end(), 0); } -}; \ No newline at end of file +};