1506. Find Root of N-Ary Tree
Содержание
"""
# Definition for a Node.
class Node:
def __init__(self, val=None, children=None):
self.val = val
self.children = children if children is not None else []
"""
class Solution:
def findRoot(self, tree: List['Node']) -> 'Node':
x = 0
for node in tree:
x ^= node.val
for child in node.children:
x ^= child.val
return next(node for node in tree if node.val == x)