Given two stringssandtwhich consist of only lowercase letters.

Stringtis generated by random shuffling stringsand then add one more letter at a random position.

Find the letter that was added int.

Example:

Input:
s = "abcd"
t = "abcde"

Output:
e

Explanation:
'e' is the letter that was added.

Subscribeto see which companies asked this question.

Hide Tags

Hash Table

Bit Manipulation

Hide Similar Problems

(E) Single Number


public class Solution {
    public char findTheDifference(String s, String t) {
        int result = 0;
        for(char c : s.toCharArray()){
            result ^= c;
        }
        for(char c : t.toCharArray()){
            result ^= c;
        }
        return (char)result;
    }
}

results matching ""

    No results matching ""