https://oj.leetcode.com/tag/tree/
模板
http://www.ninechapter.com/solutions/dfs-template/遍历(输入结果收集器不可并行)或分治(后序返回结果可并行)
http://www.ninechapter.com/solutions/bfs-template/ 进入每层前保存size
#0 分治
http://lintcode.com/en/problem/lowest-common-ancestor/
C17: https://oj.leetcode.com/problems/balanced-binary-tree/
http://lintcode.com/zh-cn/problem/insert-node-in-a-binary-search-tree/
http://lintcode.com/en/problem/remove-node-in-binary-search-tree/
https://oj.leetcode.com/problems/binary-tree-maximum-path-sum/ (难)
#1 遍历
DFS:in-order, pre-order, post-order 递归非递归
https://oj.leetcode.com/tag/depth-first-search/
BFS:level-order 只能非递归
https://oj.leetcode.com/tag/breadth-first-search/
Recursive VS Iterative
先序 递归 非递归(Stack (访问;push右;push左)先右后左)
C4: https://oj.leetcode.com/problems/binary-tree-preorder-traversal/ (基)
C11: https://oj.leetcode.com/problems/path-sum/
C12: https://oj.leetcode.com/problems/path-sum-ii/
C13: https://oj.leetcode.com/problems/sum-root-to-leaf-numbers/
中序 递归 非递归(Stack (边往左边push左;pop;访问;往右一个))
C3: https://oj.leetcode.com/problems/binary-tree-inorder-traversal/ (基)
C18: https://oj.leetcode.com/problems/validate-binary-search-tree/ (二叉搜索树) 类似C24
http://lintcode.com/en/problem/search-range-in-binary-search-tree/
C21: https://oj.leetcode.com/problems/recover-binary-search-tree/ (二叉搜索树)
https://oj.leetcode.com/problems/binary-search-tree-iterator/ 实现二叉树中序Iterator
后序 递归 非递归(反着先序 然后reverse结果)
C5: https://oj.leetcode.com/problems/binary-tree-postorder-traversal/
https://oj.leetcode.com/problems/binary-tree-upside-down/
C24: https://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/ 类似C18
层序 不能递归
使用Queue
C6: https://oj.leetcode.com/problems/binary-tree-level-order-traversal/
C7: https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/
C8: https://oj.leetcode.com/problems/binary-tree-zigzag-level-order-traversal/
C15: https://oj.leetcode.com/problems/symmetric-tree/ (层序或者递归类似于same tree)
https://leetcode.com/problems/binary-tree-right-side-view/
有next指针 不使用Queue
C9: https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/
C10: https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ (难)
#2 树上的递归
求和
C11: https://oj.leetcode.com/problems/path-sum/
C12: https://oj.leetcode.com/problems/path-sum-ii/
C13: https://oj.leetcode.com/problems/sum-root-to-leaf-numbers/
https://oj.leetcode.com/problems/binary-tree-maximum-path-sum/ (后序)
比较
C14: https://oj.leetcode.com/problems/same-tree/
C15: https://oj.leetcode.com/problems/symmetric-tree/ 与same tree区别很小
高度
C16:
https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ 分治 BFS更快
https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/ 分治
C17: https://oj.leetcode.com/problems/balanced-binary-tree/
#3 二叉搜索树 Binary Search Tree
C18: https://oj.leetcode.com/problems/validate-binary-search-tree/ (中序) 类似C24
http://lintcode.com/en/problem/search-range-in-binary-search-tree/
C19: https://oj.leetcode.com/problems/unique-binary-search-trees/ (DP)
C20: https://oj.leetcode.com/problems/unique-binary-search-trees-ii/
C21: https://oj.leetcode.com/problems/recover-binary-search-tree/ (中序)
http://lintcode.com/zh-cn/problem/insert-node-in-a-binary-search-tree/
http://lintcode.com/en/problem/remove-node-in-binary-search-tree/
#4 构造树
C22: https://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
C23: https://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ (重)
C24: https://oj.leetcode.com/problems/flatten-binary-tree-to-linked-list/ 类似C18
C25: https://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
C26: https://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/
#5 平衡二叉树 Balanced Binary Tree
C17: https://oj.leetcode.com/problems/balanced-binary-tree/