Skip to content

Commit

Permalink
Update Find the Difference
Browse files Browse the repository at this point in the history
  • Loading branch information
hikjik committed Sep 25, 2023
1 parent e0b893d commit b0ddcd8
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions solutions/find-the-difference/solution.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#pragma once

#include <numeric>
#include <string>
#include <unordered_map>

class Solution {
public:
static char findTheDifference(std::string s, std::string t) {
std::unordered_map<char, int> 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);
}
};
};

0 comments on commit b0ddcd8

Please sign in to comment.