mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
25 lines
541 B
C++
25 lines
541 B
C++
#include <algorithm>
|
|
#include <array>
|
|
#include <string>
|
|
|
|
class Solution {
|
|
public:
|
|
bool isAnagram(const std::string &s, const std::string &t) {
|
|
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;
|
|
}
|
|
}
|
|
|
|
return std::all_of(counter.begin(), counter.end(),
|
|
[](auto c) { return c == 0; });
|
|
}
|
|
};
|