My C++ solution


  • 0
    C
    class Solution {
    public:
        char findTheDifference(string s, string t) 
        {
            string::size_type bags[26];
            memset(bags, 0, sizeof(bags));
            
            for(auto ch : t)
                bags[ch - 'a'] += 1;
                
            for(auto ch : s)
                bags[ch - 'a'] -= 1;
            
            for(int i = 0; i < 26; i++)
                if(bags[i] == 1)
                    return i + 'a';
            
            return 0;
        }
    };
    

Log in to reply
 

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