LeetCode 練習問題集
問題 | 難易度 | 重要度 | テクニック |
★★★ | 高 | 二分木の再構築 | |
★★★ | 高 | 二分木の再構築 | |
★★★★ | 中 | Serialize and Reconstruct Binary Tree (シリアライズと再構築) | |
★★★★ | 中 | Serialize and Reconstruct Binary Tree (シリアライズと再構築) | |
★★★★ | 中 | Serialize and Reconstruct Binary Tree (シリアライズと再構築) |
巡回から二分木の再構築
ここでいう木の再構築とは、2種類の巡回の出力から二分木を復元することを指します。ただし前提として木の値がユニークである必要があります。なぜなら同じ値が巡回の出力に存在する場合、どのノードであるかが特定できないためです。例えば以下の2つの二分木は別の構造をとりますが、全ての巡回で出力が同じ
[1, 1]
となります。![notion image](https://www.notion.so/image/https%3A%2F%2Fstorage.interviewcat.dev%2Fcoding-interviewcat%2FBinaryTree%2F3_intermediate-ReconstructBT_HashBST%2F0_introduction%2Finvalid_binary_tree.png?table=block&id=71bc0ed3-f0c7-4b4e-8507-aa51fd2b4cf1&cache=v2)
preorder = [1, 1] inorder = [1, 1] postorder = [1, 1]