Class Solution
java.lang.Object
g1401_1500.s1436_destination_city.Solution
1436 - Destination City.<p>Easy</p>
<p>You are given the array <code>paths</code>, where <code>paths[i] = [cityA<sub>i</sub>, cityB<sub>i</sub>]</code> means there exists a direct path going from <code>cityA<sub>i</sub></code> to <code>cityB<sub>i</sub></code>. <em>Return the destination city, that is, the city without any path outgoing to another city.</em></p>
<p>It is guaranteed that the graph of paths forms a line without any loop, therefore, there will be exactly one destination city.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> paths = [[“London”,“New York”],[“New York”,“Lima”],[“Lima”,“Sao Paulo”]]</p>
<p><strong>Output:</strong> “Sao Paulo”</p>
<p><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”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> paths = [[“B”,“C”],[“D”,“B”],[“C”,“A”]]</p>
<p><strong>Output:</strong> “A”</p>
<p><strong>Explanation:</strong> All possible trips are:</p>
<p>“D” -> “B” -> “C” -> “A”.</p>
<p>“B” -> “C” -> “A”.</p>
<p>“C” -> “A”.</p>
<p>“A”. Clearly the destination city is “A”.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> paths = [[“A”,“Z”]]</p>
<p><strong>Output:</strong> “Z”</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= paths.length <= 100</code></li>
<li><code>paths[i].length == 2</code></li>
<li><code>1 <= cityA<sub>i</sub>.length, cityB<sub>i</sub>.length <= 10</code></li>
<li><code>cityA<sub>i</sub> != cityB<sub>i</sub></code></li>
<li>All strings consist of lowercase and uppercase English letters and the space character.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
destCity
-