Part 1:Traversal Binary Tree
Binary Tree Preorder Traversal
Binary Tree Inorder Traversal
Binary Tree Postorder Traversal
Binary Tree Level Order Traversal
Binary Tree Level Order Traversal II
Binary Tree Zigzag Level Order Traversal
这些题是二叉树的几种遍历:前序中序后序,层序遍历。以及最后一道是层序遍历的一个变体:之字遍历。之字遍历与普通层序遍历的不同之处在于需要区分奇偶层,来采取对应的措施:正序输出还是逆序辠�节点在中序遍历的位置,这样就能划分左子树和右子树的索引了。接着再递归构造即可。
后序遍历和中序遍历确定树也是相同的道理,不过取根节点的时候是从后往前取。递归的参数也有所不同。
Part 3:Path
Path Sum
Path Sum II
Path Sum III
Binary Tree Maximum Path Sum
Binary Tree Paths
Maximum Depth of Binary Tree
Minimum Depth of Binary Tree
Sum of Left Leaves
Count Complete Tree Nodes
这几道与路径有关的题,几乎都是 DFS 的应用,所以递归是基本套路。再熟悉熟悉~
Part 4:BFS
Binary Tree Right Side View
Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node II
Flatten Binary Tree to Linked List
这些题是 BFS 的应用,基本用迭代解决。
Part 5:inorder traversal
Convert Sorted Array to Binary Search Tree
Kth Smallest Element in a BST
Recover Binary Search Tree
这几道是中序遍历的应用,都是很机智的解法。中序遍历一般与 BST 的合作比较紧密。看到与 BST 相关的题一定不要忘了中序遍历,说不定就是一条很好的出路。
Part 6:
Balanced Binary Tree
Delete Node in a BST
Invert Binary Tree
Same Tree
Symmetric Tree
这些是一些删除节点反转二叉树等等的常见题,争取做到 Bug Free。