aboutsummaryrefslogtreecommitdiffstats
path: root/1436/main.py
blob: 16291ce32f1466590e7a8775d43c9587bf1585b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
import typing


class Solution:
    def destCity(self, paths: typing.List[typing.List[str]]) -> str:
        one = {}
        for path in paths:
            one[path[0]] = path[1]

        dest = one[paths[0][0]]
        while dest in one:
            dest = one[dest]

        return dest


def main():
    solution = Solution()
    paths = [["London", "New York"], ["New York", "Lima"], ["Lima", "Sao Paulo"]]
    print(solution.destCity(paths))


if __name__ == "__main__":
    main()