You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<strong>Explanation:</strong> Starting at "London" city you will reach "Sao Paulo" city which is the destination city. Your trip consist of: "London" ->"New York" ->"Lima" ->"Sao Paulo".
34
34
</pre>
35
35
@@ -70,7 +70,11 @@ Clearly the destination city is "A".
70
70
71
71
<!-- solution:start -->
72
72
73
-
### Solution 1
73
+
### Solution 1: Hash Table
74
+
75
+
According to the problem description, the destination city will not appear in any of the $\textit{cityA}$. Therefore, we can first traverse the $\textit{paths}$ and put all $\textit{cityA}$ into a set $\textit{s}$. Then, we traverse the $\textit{paths}$ again to find the $\textit{cityB}$ that is not in $\textit{s}$.
76
+
77
+
The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of $\textit{paths}$.
0 commit comments