Find the Difference

LeetCode題目: 389. Find the Difference

My solution:

/**
 * @param {string} s
 * @param {string} t
 * @return {character}
 */
let findTheDifference = (s, t) => {
    let map = new Map();
    for(let i=0; i<t.length; i++) {
        map.has(t[i]) ? map.set(t[i], map.get(t[i])+1) : map.set(t[i], 1);
    }
    for(let i=0; i<s.length; i++) {
        if(map.has(s[i])) map.set(s[i], map.get(s[i])-1)
        if(map.get(s[i]) === 0) map.delete(s[i]);
    }
    return map.keys().toArray().join('');
};
profile-image
Hi, 我是 Zeki。目前為一名前端工程師。我相信科技始終來自於人性,是用來幫助人們過上更有品質的生活的,但願也希望如此。