389. Find the Difference

Link

Solution

bit operation是用XOR辦到,但不是很懂XOR的妙用邏輯

    public char findTheDifference(String s, String t) {
        char ret = 0;
        for(int i = 0; i < s.length(); i++){
            ret += t.charAt(i) - s.charAt(i);
        }
        ret += t.charAt(t.length()-1);
        return ret;
    }

Last updated

Was this helpful?