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