An Easy 4ms 4-line C++ Solution


  • 0
    Y
    class Solution {
    public:
        char findTheDifference(string s, string t) {
            int ans = 0;
            for(int i = 0 ; i < s.length(); ++i) ans ^= s[i]^t[i];
            ans ^= t[t.length() - 1];
            return char(ans);
        }
    };
    

Log in to reply
 

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