root
,返回 它的 后序 遍历 。[7, 9, 4, null, null, 5, 6, 8, 1, 2, 6, 9, null, 6, 6, 8]
[9, 8, 8, 1, 5, 2, 6, 6, 4, 7]
import json class Node: def __init__(self, data): self.value = data self.left = None self.right = None def __repr__(self): return "" % (self.value, self.left, self.right) st = json.loads(input()) head = Node(st.pop(0)) l = [head] while st: cnt = len(l) * 2 lc = [] while st and cnt: cnt -= 1 lc.append(Node(n) if (n := st.pop(0)) else None) j = 0 for i in l: if i and j < len(lc): i.left = lc[j] j += 1 if j < len(lc): i.right = lc[j] j += 1 l = lc ... ...