C++ Solution With Bit Manipulation


  • 0
    B

    The idea to solve this problem is the same as finding the only single number in many repeated numbers.

    class Solution {
    public:
         char findTheDifference(std::string s, std::string t) {
            char appended_letter = static_cast<char>(0);
            for(char letter_in_s:s){
                appended_letter^=letter_in_s;
            }
            for(char letter_in_t:t){
                appended_letter^=letter_in_t;
            }
            return appended_letter;
        }

Log in to reply
 

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