前往此题

解题思路

题目的意思是要我们找出线路的终点没有被作为起点的那个站。所以我们只需要2步就能解决这道题

将所有起点放入数组中lines, 查找所有线路,不存在于lines中的站点就是最后的终点站

代码

class Solution:
    def destCity(self, paths: List[List[str]]) -> str:
        if not paths: return ""
        start = [path[0] for path in paths]

        for path in paths:
            if path[1] not in start:
                return path[1]