mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
44 lines
2.1 KiB
HTML
44 lines
2.1 KiB
HTML
<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> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> paths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]
|
|
<strong>Output:</strong> "Sao Paulo"
|
|
<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".
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> paths = [["B","C"],["D","B"],["C","A"]]
|
|
<strong>Output:</strong> "A"
|
|
<strong>Explanation:</strong> All possible trips are:
|
|
"D" -> "B" -> "C" -> "A".
|
|
"B" -> "C" -> "A".
|
|
"C" -> "A".
|
|
"A".
|
|
Clearly the destination city is "A".
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> paths = [["A","Z"]]
|
|
<strong>Output:</strong> "Z"
|
|
</pre>
|
|
|
|
<p> </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>
|