The title

Paths [I] = [cityAi, cityBi] indicates that the paths will go directly from cityAi to cityBi. Find the final destination of the tour, a city that does not have any route to any other city.

The problem data guarantees that the circuit diagram will form a circuit with no loops, so there will be only one travel destination.

 

Example 1: Enter: Paths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"] It starts at London and ends at Sao Paulo. The itinerary for this trip is "London" -> "New York" -> "Lima" -> "Sao Paulo". Example 2: input: paths = [[" B ", "C"], [" D ", "B"], [" C ", "A"]] output: "A" explanation: all possible routes are:  "D" -> "B" -> "C" -> "A". "B" -> "C" -> "A". "C" -> "A". "A". Obviously, the end of the trip is "A". Example 3: Enter: Paths = [["A","Z"]]Copy the code

Tip:

1 <= paths.length <= 100 paths[i].length == 2 1 <= cityAi.length, cityBi.length <= 10 cityAi ! = cityBi All characters consist of uppercase and lowercase letters and Spaces.

Their thinking

Class Solution: def destCity(self, paths: List[List[STR]]) -> STR: self, paths: List[List[STR]] For index,val in enumerate(iList): if val in resDict: del resDict[val] else: if val in resDict: del resDict (iList) ResDict [val] = index for key,val in resdict.items (): #val== 1: return key if __name__ == '__main__': paths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]] ret = Solution().destCity(paths) print(ret)Copy the code