389. Find the Difference

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public char findTheDifference(String s, String t) {
int res = 0;
for (int i = 0; i < s.length(); i++) {
res ^= s.charAt(i);
res ^= t.charAt(i);
}
res ^= t.charAt(t.length() - 1);
return (char) res;
}
}

References

389. Find the Difference