2023-12-17 18:36:53 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class Solution {
|
2024-01-03 12:06:42 +01:00
|
|
|
public:
|
|
|
|
bool isAnagram(const std::string &s, const std::string &t) {
|
2023-12-17 18:36:53 +01:00
|
|
|
std::array<int, 26> counter{};
|
|
|
|
|
|
|
|
for (char c : s) {
|
|
|
|
counter[c - 'a']++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (char c : t) {
|
|
|
|
counter[c - 'a']--;
|
|
|
|
|
|
|
|
if (counter[c - 'a'] < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
return std::all_of(counter.begin(), counter.end(),
|
|
|
|
[](auto c) { return c == 0; });
|
2023-12-17 18:36:53 +01:00
|
|
|
}
|
|
|
|
};
|