5 lines C++ solution


  • 0
    J
    class Solution {
    public:
        char findTheDifference(string s, string t) {
            
            // vector<int> table(26,0);
            
            // for(auto& c : s)
            //     table[c-'a']++;
              
            // for(auto& c : t){
            //   if(table[c-'a'] == 0)
            //     return c;
            //   else
            //     table[c-'a']--;
            
            // }
            
            
            // return '\0';
            
            
            long ss = 0;
            for(int i = 0; i < s.size(); i++)
                ss += t[i]-s[i];
            
            ss += t.back();
            
            return ss;
        }
    };
    

Log in to reply
 

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