[LeetCode]#1436. Destination City

Input: paths = [["B","C"],["D","B"],["C","A"]]
Output: "A"
  1. Create Hash Table for path
  2. Search all string list in Hash Table
  3. If string doesn’t have pair, return it.
import collections
class Solution:
def destCity(self, paths):
hashtable = collections.defaultdict(str)

ls = []

for a,b in paths:
hashtable[a] = b
ls += a,
ls += b,

for ans in ls:
if hashtable[ans] == "":
return ans

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.