simple cpp solution


  • 0
    U
    class Solution {
    public:
        char findTheDifference(string s, string t) {
            int cache[26] = {0};
            for(unsigned u=0; u<s.size(); u++)
            {
                cache[s[u] - 'a']++;
                cache[t[u] - 'a']--;
            }
            cache[t[t.size()-1] - 'a']--;
            for(int i=0; i<26; i++)
            {
                if(cache[i] != 0)return 'a' + i;
            }
            return 'a';
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.