// Given two strings s and t, return true if t is an anagram of s, and false otherwise. // Example 1: // Input: s = "anagram", t = "nagaram" // Output: true // Example 2: // Input: s = "rat", t = "car" // Output: false #include #include #include using namespace std; class Solution { public: bool isAnagram(string s, string t) { vector table(26); if (s.size() != t.size()) return false; for (int i = 0; i < s.size(); i++) { table[(int)s[i] - 'a'] += 1; table[(int)t[i] - 'a'] -= 1; } for (auto i : table) { if (i != 0) return false; } return true; } }; int main() { string s = "car"; string t = "rat"; Solution so; cout << so.isAnagram(s, t) << endl; }