#389
Easy Algorithms Find the difference
Hash Table String Bit Manipulation Sorting
60.1% acceptance
Jan 12, 2026
5452
516
You are given two strings s and t.
String t is generated by random shuffling string s and then add one more letter at a random position.
Return the letter that was added to t.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn find_the_difference(s: String, t: String) -> char {
let mut xor = 0u8;
for b in s.bytes() {
xor ^= b;
}
for b in t.bytes() {
xor ^= b;
}
xor as char
}
}