Skip to content

Commit 57c9d76

Browse files
authored
389. Find the Difference
1 parent 90f3142 commit 57c9d76

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

389. Find the Difference

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
So, here also let's say our character are:
2+
s = abc
3+
t = cabx
4+
5+
if we take XOR of every character. all the n character of s "abc" is similar to n character of t "cab". So, they will cancel each other.
6+
And we left with our answer.
7+
8+
s = abc
9+
t = cbax
10+
------------
11+
ans -> x
12+
13+
char findTheDifference(string s, string t) {
14+
char c = 0;
15+
for(char cs : s) c^=cs; //Xoring all charecter to extract unique one
16+
for(char ct : t) c^=ct;
17+
return c;
18+
}

0 commit comments

Comments
 (0)