題解 | #二叉樹遍歷#
二叉樹遍歷
http://fangfengwang8.cn/practice/4b91205483694f449f94c179883c1fef
s = input() stack = []#棧實現(xiàn)中序輸出 ps:若是隊列,則是中序 ans = [] for x in s: if x != "#": stack.append(x) else: if stack: ans.append(stack.pop()) h = " ".join(ans) + " " print(h)