242. Valid Anagram

class Solution { public: bool isAnagram(string s, string t) { unordered_map<char, int> m; for (char & ss: s) m[ss]++; for (char & tt: t){ if (m.find(tt) == m.end()) return false; else m[tt]--; } for (auto & it: m){ if (it.second != 0) return false; } return true; } };
One pass...

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.