clueless coding // TODO: be smarter

LeetCode Valid Anagram: CPP Solution



TL;DR Code Solution


bool isAnagram(string s, string t) {

    unordered_map<char, int> map;
    for (int i = 0; i < s.length(); i++) {
        map[s[i]]++;
    }

    for (int i = 0; i < t.length(); i++) {
        map[t[i]]--;
    }

    for (unordered_map<char, int>::iterator it = map.begin(); it != map.end(); it++) {
        if (it->second != 0) {
            return false;
        }
    }

    return true;

}