[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

--

--

--

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Creating an aggressive enemy that ram to the player in Unity.

PortSwigger Lab: Modifying serialized objects | WalkThrough

Load Balance and Scale Node.js Containers with Nginx and Docker Swarm

String Associative Array and CombSort Benchmark 2021 Edition

Benefits of coding

Revoland Enters Listings, Having Raised $10.6M In Seed and Pre-sale Rounds

Cloudbusting

Tutorial Fuzzy Logic Mamdani for Arduino

Tutorial Fuzzy Logic Mamdani for Arduino

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.

More from Medium

Sorting Algorithms Explained Using Python: Heap Sort

Glass Cube and Dots

LeetCode Patterns Adventure 17 — Binary Search

LeetCode #1332 | Remove Palindromic Subsequences

Hackerrank — Merge Sorted Linked list walkthrough #Python #Hackerrank