题目:原题链接(中等)

标签:树、哈希表

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N ) O(N) O(N) O ( N ) O(N) O(N) 144ms (90.00%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:
    def findRoot(self, tree: List['Node']) -> 'Node':
        maybe = set(tree)
        for n1 in tree:
            for n2 in n1.children:
                maybe.remove(n2)
        return maybe.pop()