A. 還原 BST 並輸出中序遍歷(含空節點)

    Type: Default 256ms 256MiB

還原 BST 並輸出中序遍歷(含空節點)

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

題目描述

給定一組字串表示的整數陣列,為一棵 二元搜尋樹(BST)層序遍歷結果,其中 "null" 表示對應位置上為空節點。請你根據這組輸入還原出這棵 BST,並輸出其 中序遍歷 的結果。

輸入格式

第一行一個整數 nn,表示層序輸入的節點數量(包括 "null")。
第二行 nn 個用空格分隔的字串,為節點值或 "null"

輸出格式

輸出一行整數,為還原 BST 的中序遍歷結果,數字之間以空格分隔。

輸入範例

9
5 3 8 1 4 6 9 null null

輸出範例

1 3 4 5 6 8 9

資料範圍

  • 1n1041 \leq n \leq 10^4
  • 合法數字節點為 11 \leq 節點值 109\leq 10^9
  • "null" 表示空節點,不會插入

20250516_C++_樹_練習

Not Claimed
Status
Done
Problem
2
Open Since
2025-5-15 0:00
Deadline
2025-5-24 23:59
Extension
24 hour(s)