Problem 389: Find the Difference
思路
使用异或关系判断
public class Solution {
public char findTheDifference(String s, String t) {
char ans = 0;
for (int i = 0; i < s.length(); i++) {
ans ^= s.charAt(i);
}
for (int i = 0; i < t.length(); i++) {
ans ^= t.charAt(i);
}
return ans;
}
}
Last updated
Was this helpful?