# 二元樹練習題 (Binary tree)
## 二元樹的遍歷
| 題號 | 題目 | 難度 | 備註 | 題解 |
| -------- | -------- | -------- | -------- | -------- |
|144|[Binary tree preorder traversal 二元樹的前序遍歷](https://leetcode.cn/problems/binary-tree-preorder-traversal/)|<font color=DarkGreen>Easy</font>||[二元樹的前序遍歷題解](https://hackmd.io/@paxton0222/Sy6r2p-Ro)|
|94|[Binary tree inorder traversal 二元樹的中序遍歷](https://leetcode.cn/problems/binary-tree-inorder-traversal/)|<font color=DarkGreen>Easy</font>||[二元樹的中序遍歷題解](https://hackmd.io/@paxton0222/B1m6npbCs)|
|145|[Binary tree postorder traversal 二元樹的後序遍歷](https://leetcode.cn/problems/binary-tree-postorder-traversal/)|<font color=DarkGreen>Easy</font>||[二元樹的後序遍歷題解](https://hackmd.io/@paxton0222/Hk3fa6W0i)|
|102|[Binary tree level order traversal 二元樹的層序遍歷](https://leetcode.cn/problems/binary-tree-level-order-traversal/)|<font color=Orange>Meduim</font>||[二元樹的層序遍歷題解](https://hackmd.io/@paxton0222/S1L9T6-Ai)|
|107|[Binary tree level order traversal II 二元樹的層序遍歷 2](https://leetcode.cn/problems/binary-tree-level-order-traversal-ii/)|<font color=Orange>Meduim</font>|二元樹層序遍歷變化題|
|103|[Binary tree zigzg level order traversal 二元樹的鋸齒形層序遍歷](https://leetcode.cn/problems/binary-tree-zigzag-level-order-traversal/)|<font color=Orange>Meduim</font>|二元樹層序遍歷變化題|[Binary Tree ZigZag Level Order Traversal 題解](https://hackmd.io/@paxton0222/rJd-p9wcn)|
## 二元樹變化題
| 題號 | 題目 | 難度 | 備註 | 題解 |
| -------- | -------- | -------- | -------- | -------- |
|530|[Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst/description/?envType=study-plan-v2&envId=top-interview-150)|<font color=DarkGreen>Easy</font>|BST inorder traversal|[Minimum Absolute Difference in BST 題解](https://hackmd.io/@paxton0222/SJoLVX8c2)|
|104|[Maximun depth of binary tree 二元樹的最大深度](https://leetcode.cn/problems/maximum-depth-of-binary-tree/)|<font color=DarkGreen>Easy</font>||[二元樹的最大深度題解](https://hackmd.io/@paxton0222/rJcHXAWRs)|
|110|[Balanced binary tree 判斷平衡二元樹](https://leetcode.cn/problems/balanced-binary-tree/submissions/)|<font color=DarkGreen>Easy</font>||[判斷平衡二元樹題解](https://hackmd.io/@paxton0222/ByTsuoeCs)
|111|[Balanced binray tree 平衡二元樹](https://leetcode.cn/problems/balanced-binary-tree/)|<font color=DarkGreen>Easy</font>|||
|226|[Invert binary tree 翻轉二元樹](https://leetcode.cn/problems/invert-binary-tree/)|<font color=DarkGreen>Easy</font>||[Invert Binary Tree 題解](https://hackmd.io/@paxton0222/BknjHJ3Yn)|
|104|[Maximum depth of binary tree 二元樹的最大深度](https://leetcode.cn/problems/maximum-depth-of-binary-tree/)|<font color=DarkGreen>Easy</font>||[Maximum depth of binary tree 題解](https://hackmd.io/@paxton0222/HkORsAsKh)|
|100|[Same tree 相同的樹](https://leetcode.cn/problems/same-tree/)|<font color=DarkGreen>Easy</font>|中序遍歷比較題|[相同的樹題解](https://hackmd.io/@paxton0222/Skmxo6SAs)|
|101|[Symmetric tree 對稱二元樹](https://leetcode.cn/problems/symmetric-tree/)|<font color=DarkGreen>Easy</font>|中序遍歷比較+翻轉二元樹|[對稱二元樹題解](https://hackmd.io/@paxton0222/SkD87RrCo)|
|404|[Sum of left leaves 左葉子節點的和](https://leetcode.com/problems/sum-of-left-leaves/description/)|<font color=DarkGreen>Easy</font>||[左葉子節點的和](https://hackmd.io/@paxton0222/B1l5vvOg3)|
|543|[Diameter of binary tree 二元樹的直徑](https://leetcode.com/problems/diameter-of-binary-tree/description/)|<font color=DarkGreen>Easy</font>||[二元樹的直徑題解](https://hackmd.io/@paxton0222/rJr9fRZx2)|
|637|[Average of levels in binary tree 二元樹每層的平均樹](https://leetcode.com/problems/average-of-levels-in-binary-tree/description/)|<font color=DarkGreen>Easy</font>||[Average Of Levels In Binary Tree 題解](https://hackmd.io/@paxton0222/BkK7qcD53)|
|572|[Subtree of Anthor Tree](https://leetcode.com/problems/subtree-of-another-tree/description/)|<font color=DarkGreen>Easy</font>||[Subtree of Anthor Tree 題解](https://hackmd.io/@paxton0222/BJhpi8EC2)|
|98|[Validate binary search tree 驗證二元搜尋樹](https://leetcode.cn/problems/validate-binary-search-tree/)|<font color=Orange>Meduim</font>|||
|99|[Recover binary search tree 恢復二元搜尋樹](https://leetcode.cn/problems/recover-binary-search-tree/)|<font color=Orange>Meduim</font>|||
|112|[Path Sum 路徑總和](https://leetcode.cn/problems/path-sum/)|<font color=Orange>Meduim</font>||[Path Sum 題解](https://hackmd.io/@paxton0222/rk5yU1ec2)|
|113|[Path Sum II 路徑總和 II](https://leetcode.cn/problems/path-sum-ii/)|<font color=Orange>Meduim</font>|||
|114|[Flatten binary tree to linked list 二元樹展開為鏈表](https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/)|<font color=Orange>Meduim</font>|||
|116|[Populating next right pointers in each node 填充每個節點的下一個右側節點](https://leetcode.cn/problems/populating-next-right-pointers-in-each-node/)|<font color=Orange>Meduim</font>|||
|117|[Populating next right pointers in each node II 填充每個節點的下一個右側節點 II](https://leetcode.cn/problems/populating-next-right-pointers-in-each-node-ii/)|<font color=Orange>Meduim</font>|||
|129|[Sum root to leaf numbers 求根節點到所有葉子節點的總和](https://leetcode.cn/problems/sum-root-to-leaf-numbers/)|<font color=Orange>Meduim</font>|||
|199|[Binary tree right side view 二元樹的右側視圖](https://leetcode.cn/problems/binary-tree-right-side-view/)|<font color=Orange>Medium</font>||[Binary Tree Right Side View 題解](https://hackmd.io/@paxton0222/rk1ovcD53)|
|222|[Count complete tree nodes 完全二元樹的節點總數](https://leetcode.cn/problems/count-complete-tree-nodes/)|<font color=Orange>Meduim</font>|||
|230|[Kth smallest in a bst 二元樹第K小的節點](https://leetcode.cn/problems/kth-smallest-element-in-a-bst/)|<font color=Orange>Meduim</font>|||
|257|[Binary tree paths 二元樹的所有路徑](https://leetcode.cn/problems/binary-tree-paths/)|<font color=Orange>Meduim</font>|||
|655|[Pring binary tree 輸出二元樹](https://leetcode.cn/problems/print-binary-tree/)|<font color=Orange>Meduim</font>|照著提示寫||
|117|[Populating Next Right Pointers in Each Node II](https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/description/)|<font color=Orange>Meduim</font>||[Populating Next Right Pointers in Each Node II 題解](https://hackmd.io/@paxton0222/r1RqfWaFn)|
|124|[Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/description/?envType=study-plan-v2&envId=top-interview-150)|<font color=Red>Hard</font>|篩選出二元樹中的最大總和值路徑(Path)|[Binary Tree Maximum Path Sum 題解](https://hackmd.io/@paxton0222/H12rcWVq3)|
|129|[Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/description/?envType=study-plan-v2&envId=top-interview-150)|<font color=Orange>Meduim</font>||[Sum Root to Leaf Numbers 題解](https://hackmd.io/@paxton0222/SJ_tqZV92)|
|433|[Minimum Genetic Mutation](https://leetcode.com/problems/minimum-genetic-mutation/description/?envType=study-plan-v2&envId=top-interview-150)|<font color=Orange>Meduim</font>|字串 BFS|[Minimum Genetic Mutation 題解](https://hackmd.io/@paxton0222/ryORTzVcn)|
|230|[Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/description/?envType=study-plan-v2&envId=top-interview-150)|<font color=Orange>Meduim</font>|BST inorder traversal|[Kth Smallest Element in a BST 題解](https://hackmd.io/@paxton0222/SJ89xEIq2)|
|98|[Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/description/?envType=study-plan-v2&envId=top-interview-150)|<font color=Orange>Meduim</font>|BST inorder traversal|[Validate Binary Search Tree 題解](https://hackmd.io/@paxton0222/BJ1Ys4I93)|
|138|[Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/description/?envType=study-plan-v2&envId=top-interview-150)|<font color=Orange>Meduim</font>||[Copy List with Random Pointer 題解](https://hackmd.io/@paxton0222/rJKgsvUc2)|
|652|[Find Duplicate Subtrees](https://leetcode.com/problems/find-duplicate-subtrees/description/)|<font color=Orange>Meduim</font>||[Find Duplicate Subtrees 題解](https://hackmd.io/@paxton0222/BJwVK2nqh)
|222|[Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes/?envType=study-plan-v2&envId=top-interview-150)|<font color=Orange>Meduim</font>||[Count Complete Tree Nodes 題解](https://hackmd.io/@paxton0222/S13_lKP5n)|
|108|[Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/description/?envType=study-plan-v2&envId=top-interview-150)|<font color=Orange>Meduim</font>||[Convert Sorted Array to Binary Search Tree 題解](https://hackmd.io/@paxton0222/HyQZZVh6n)|
|173|[Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator/)|<font color=Orange>Meduim</font>| BST inorder traversal|[Binary Search Tree Iterator 題解](https://hackmd.io/@paxton0222/HkmK07Q0n)|
## 二元樹的最近公共祖先 (LCA)
| 題號 | 題目 | 難度 | 備註 | 題解 |
| -------- | -------- | -------- | -------- | -------- |
|235|[Lowest ancestor of a binary search tree 二元搜尋樹的最近公共祖先](https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-search-tree/)|<font color=Orange>Meduim</font>|根據二元搜尋樹的特性找到 **small.val < current.val < large.val**,符合條件的就是最近公共祖先|[二元搜尋樹的最近公共祖先題解](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/solutions/1347857/c-java-python-iterate-in-bst-picture-explain-time-o-h-space-o-1/)|
|236|[Lowest ancestor of a binary tree 二元樹的最近公共祖先](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/description/)|<font color=Orange>Meduim</font>| Post order traversal |[二元樹的最近公共祖先題解](https://hackmd.io/@paxton0222/B1424Z4A3)|
## 唯一決定二元樹
| 題號 | 題目 | 難度 | 備註 | 題解 |
| -------- | -------- | -------- | -------- | -------- |
|105|[Construct binary tree from preorder and inorder traversal 從前序與中序遍歷序列構造二元樹](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description/)|<font color=Orange>Meduim</font>||[Construct Binary Tree Form Preorder And Inorder Traversal 題解](https://hackmd.io/@paxton0222/SkmcR16Y3)|
|106|[Construct binary tree from inorder and postorder traversal 從中序與後續遍歷序列構造二元樹](https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/)|<font color=Orange>Meduim</font>||[Construct Binary Tree Form Inorder And Postorder Traversal 題解](https://hackmd.io/@paxton0222/S1ZPagTF2)|