Posted on

Description

Submission

class Solution {
    int freq[26];
public:
    char findTheDifference(string s, string t) {
        for(char ch: t) {
            ++freq[ch-'a'];
        }

        for(char ch: s) {
            --freq[ch-'a'];
        }

        for(int i = 0; i < 26; ++i) {
            if(freq[i]) return i + 'a';
        }

        return 'a';
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *