题解 | #二叉树遍历#
二叉树遍历
https://www.nowcoder.com/practice/4b91205483694f449f94c179883c1fef
s = input() stack = []#栈实现中序输出 ps:若是队列,则是中序 ans = [] for x in s: if x != "#": stack.append(x) else: if stack: ans.append(stack.pop()) h = " ".join(ans) + " " print(h)