题解 | #二叉树遍历#
二叉树遍历
https://www.nowcoder.com/practice/6e732a9632bc4d12b442469aed7fe9ce
def ans_post(pre, mid): if not pre: return "" root = pre[0] left_mid = mid[: mid.index(root)] right_mid = mid[mid.index(root) + 1 :] left_pre = pre[1 : len(left_mid) + 1] right_pre = pre[len(left_mid) + 1 :] left_post = ans_post(left_pre, left_mid) right_post = ans_post(right_pre, right_mid) return left_post + right_post + root while True: try: pre = list(input()) mid = list(input()) print(ans_post(pre, mid)) except: break