Share my C++ solution, easy to understand


  • 0
    V
    class Solution {
    public:
        char findTheDifference(string s, string t) {
            int s_len = s.length();
            int t_len = t.length();
            char tmp = s[0];
            
            for (int i = 1; i < s_len; i++)
            {
                tmp ^= s[i];
            }
            
            for (int j = 0; j < t_len; j++)
            {
                tmp ^= t[j];
            }
            
            return tmp;
        }
    };
    

Log in to reply
 

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