15 Jun 2024C++ / Python / TypeScriptEasy

Find the Difference

Collected C++, Python, TypeScript solutions for find the difference. Add a dedicated write-up later if you want deeper notes.

auto-generated entry for Find the Difference. the solution files are available below.

solution files

  • C++ find-the-difference/synced-solution.cpp
  • Python find-the-difference/synced-solution.py
  • TypeScript find-the-difference/synced-solution.ts

Solution files

Pythonfind-the-difference/synced-solution.py
def findTheDifference(s, t):
    result = class="syntax-number">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 = class="syntax-number">0;

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

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

        return (char)result;
    }
};
TypeScriptfind-the-difference/synced-solution.ts
function findTheDifference(s: string, t: string): string {
    let result = class="syntax-number">0;

    for (const char of s) {
        result ^= char.charCodeAt(class="syntax-number">0);
    }

    for (const char of t) {
        result ^= char.charCodeAt(class="syntax-number">0);
    }

    return String.fromCharCode(result);
}