Leetcode Problem 1436. Destination City

1436. Destination City

Leetcode Solutions

Approach: Hash Set

  1. Initialize a hash set hasOutgoing.
  2. Iterate over paths and add each cityAi to hasOutgoing.
  3. Iterate over paths again and for each cityBi, check if it is not in hasOutgoing.
  4. If cityBi is not in hasOutgoing, return cityBi as it is the destination city.
  5. The code should never reach beyond this point as the destination city will be found in the loop.
UML Thumbnail

Approach: Brute Force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...