Javascript O(N) Solution


  • 0

    Main Idea:
    Use XOR operator to compare ASCII code.

    var findTheDifference = function(s, t) {
        let tArr = t.split('')
        let sum = 0
        tArr = tArr.concat(s.split(''))
        for(let i = 0; i < tArr.length; i++){
            sum ^= tArr[i].charCodeAt(0)
        }
        return String.fromCharCode(sum)
    };
    

Log in to reply
 

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