simple java solution using bit manipulation


  • 0
    J
    public char findTheDifference(String s, String t) {
            int lens=s.length(),lent=t.length();
            char result=t.charAt(lent-1);
            for(int i=0;i<lens;i++){
                result^=s.charAt(i);
                result^=t.charAt(i);
            }
            return result;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.