Problem 389

Posted by Ruizhi Ma on October 26, 2020

Solution URL

https://leetcode.com/submissions/detail/413580706/

代码

class Solution {
    public char findTheDifference(String s, String t) {
        //ans: https://leetcode-cn.com/problems/find-the-difference/solution/hua-jie-suan-fa-389-zhao-bu-tong-by-guanpengchn/
        char ans = t.charAt(t.length() - 1);

        for(int i = 0; i < s.length(); i++){
            ans ^= s.charAt(i);
            ans ^= t.charAt(i);
        }

        return ans;
    }
}