Isaac Emmanuel
15 Jun 2024•EasyC++ / Python / TypeScript

Find the Difference

C++, Python and TypeScript solutions for Find the Difference.

The Find the Difference solutions are below.

Solution files

Python•find-the-difference/synced-solution.py
def findTheDifference(s, t):
    result = 0

    for char in s:
        result ^= ord(char)

    for char in t:
        result ^= ord(char)

    return chr(result)
C++•find-the-difference/synced-solution.cpp
class Solution {
public:
    char findTheDifference(string s, string t) {
        int result = 0;

        for (char c : s) {
            result ^= c;
        }

        for (char c : t) {
            result ^= c;
        }

        return (char)result;
    }
};
TypeScript•find-the-difference/synced-solution.ts
function findTheDifference(s: string, t: string): string {
    let result = 0;

    for (const char of s) {
        result ^= char.charCodeAt(0);
    }

    for (const char of t) {
        result ^= char.charCodeAt(0);
    }

    return String.fromCharCode(result);
}