[JavaScript] Easy to understand - Map and Set
SOLUTION 1 - Map\n\nWe could use a map to store the status of city:\n\n- If it\'s a start of path, make the value plus 1.\n- If it\'s a end of path, make the va
## SOLUTION 1 - Map\n\nWe could use a map to store the status of city:\n\n- If it\'s a start of path, make the value plus 1.\n- If it\'s a end of path, make the value minus 1.\n\nFinally, most cities will be 0. The start of whole path will be 1. And the destination city will be -1.\n\n```js\nconst destCity = (paths) => {\n  const map = new Map();\n  for (const path of paths) {\n    map.set(path[0], map.has(path[0]) ? 0 : 1);\n    map.set(path[1], map.has(path[1]) ? 0 : -1);\n  }\n  for (const item of map) {\n    if (item[1] === -1) return item[0];\n  }\n};\n```\n\n## SOLUTION 2 - Set\n\nActually, we don\'t need all informations. So, we may not to store them but just a mark.\n\nHere we use a Set to store the mark:\n\n1. We mark all start of paths.\n2. The destination city must not be in this set.\n\n```js\nconst destCity = (paths) => {\n  const set = new Set();\n  for (const path of paths) set.add(path[0]);\n  for (const path of paths) {\n    if (!set.has(path[1])) return path[1];\n  }\n};\n```\n
['JavaScript']