[practice js] a naive solution...


  • 1
    M
    /**
     * @param {string} s
     * @param {string} t
     * @return {character}
     */
    var findTheDifference = function(s, t) {
        var sumOfs = 0, sumOft = 0;
        for (var i = 0; i < s.length; ++i) {
            sumOfs += s[i].charCodeAt();
        }
        for (i = 0; i < t.length; ++i) {
            sumOft += t[i].charCodeAt();
        }
        return String.fromCharCode(sumOft - sumOfs);
    };
    

Log in to reply
 

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