clueless coding // TODO: be smarter

LeetCode Find the Difference: CPP Solution



TL;DR Code Solution


char findTheDifference(string s, string t) {

    unordered_map<char, int> map;

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

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

}