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
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.
find-the-difference/synced-solution.cppfind-the-difference/synced-solution.pyfind-the-difference/synced-solution.tsdef 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)
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;
}
};
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);
}