Check Whether Two Strings are Almost Equivalent LeetCode solution in C++

1
class Solution {
2
public:
3
bool checkAlmostEquivalent(string word1, string word2) {
4
unordered_map<char, int> m;
5
for (int i = 0; i < word1.size(); i++) {
6
m[word1[i]]++;
7
}
8
for (int i = 0; i < word2.size(); i++) {
9
m[word2[i]]--;
10
}
11
for (auto i : m) {
12
if (abs(i.second) > 3) {
13
return false;
14
}
15
}
16
return true;
17
}
18
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0