Javascript Hash Table

August 08, 2017

const findTheDifference = (s, t) => {
  let hash = {}
  for (let v of [...t]) {
    hash[v] ? hash[v]++ : (hash[v] = 1)
  }
  for (let v of [...s]) {
    hash[v]--
  }
  for (let key in hash) {
    if(hash[key] === 1) return key
  }
}

Ref: https://leetcode.com/problems/find-the-difference/description/


Tagged withjavascript, algorithm

Questions, Comments, Suggestions? Open an Issue