26 Tree
二叉树
LinkedList to Tree / List / Array to Tree:
L106 Convert Sorted List to Balanced BST (109)
L378 Convert Binary Search Tree to Doubly Linked List
L453 Flatten Binary Tree to Linked List (114) - 修改树
L242 Convert Binary Tree to Linked Lists by Depth -- bfs & dfs
108 Convert Sorted Array to Binary Search Tree
Path Sum类:
L475 Binary Tree Maximum Path Sum II -- max from root to leaf
L94 Binary Tree Maximum Path Sum (124) -- max from any to any
---------感觉这几条path sum的基调都是target - node.val再递归然后判断 = node.val比加起来方便------
113 Path Sum II (L376 Binary Tree Path Sum)
437 Path Sum III -- 跟L246一样,只是这题求的是方案个数,L246求具体方案
L472 Binary Tree Path Sum III -- 有parent pointer,其实是图的遍历找target
------------------下面这几题是连续递增/递减序列------------------
298 Binary Tree Longest Consecutive Sequence(L595)-- along parent to child path Inc from up to down
L614 Binary Tree Longest Consecutive Sequence II (549) -- any to any
Tree Node Sum/Value类:
L597 Subtree with Maximum Average
501 Find Mode in Binary Search Tree
1022 Sum of Root To Leaf Binary Numbers
Lowest Common Ancestor类:
235 Lowest Common Ancestor of a BST
236 Lowest Common Ancestor of a Binary Tree (L88)
L474 Lowest Common Ancestor II -- 有parent pointer,链表intersection很像。
L578 Lowest Common Ancestor III - 要找的点可能不在树里
1257 Smallest Common Region -- 像有parent的那题,结构有点不一样
判断树:
L467 Complete Binary Tree - 要补code
100 Same Tree (L469)
L470 Tweaked identical Binary Tree
101 Symmetric Tree (L468)
98 Valid Binary Search Tree (L95)
110 Balanced Binary Tree (L93)
255 Verify Preorder Sequence in BST -- 单调栈
L245 Subtree (572) -- preorder + "#" 可以uniquely identify a tree
修改树:
226 Invert Binary Tree (L175)
116 Populating Next Right Pointers in Each Node
117 Populating Next Right Pointers in Each Node II
156 Binary Tree Upside Down 感觉是在修改特殊的链表
538 Convert BST to Greater Tree (L661)
基本变形考:
173 Binary Search Tree Iterator (L86) - inorder
222 Count Complete Tree Nodes - 满二叉树变种考法
230 Kth Smallest Element in a BST - 中序遍历or分治(分治做法比较像median那题)
671 Second Minimum Node In a Binary Tree
Traversal Related:
270 Closest Binary Search Tree Value - pramp 3 - TreeSet flooring / celing / lower / higher
272 Closest Binary Search Tree Value II -- 可以转化为 L460 K closest in sorted Arrays
257 Binary Tree Paths (L480)
366 Find Leaves of Binary Tree (L650)
L11 Search Range in Binary Search Tree
510 Inorder Successor in BST II
1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree
BFS:
102 Binary Tree Level Order Traversal (L69) -- 对角线打印矩阵
107 Binary Tree Level Order Traversal II (L70)
103 Binary Tree Zigzag Level Order Traversal (L71) -- L185 Matrix Zigzag Traversal
513 Find Bottom Left Tree Value -- bfs
515 Find Largest Value in Each Tree Row -- bfs
199 Binary Tree Right Side View
637 Average of Levels in Binary Tree
建树:
105 Construct Binary Tree from Preorder and Inorder Traversal (L73)
106 Construct Binary Tree form Inorder and Postorder Traversal (L72)
536 Construct Binary Tree from String
其他:
104 Maximum Depth of Binary Tree (L97)
L155 Minimum Depth of Binary Tree (111)
337 House Robber III (L534)
96 Unique Binary Search Tree -- catalan number DP
95 Unique Binary Search Trees II -- 搜索
Serilize or Deserialize Tree:
297 Serialize and Deserialize Binary Tree (L7)
449 Serialize and Deserialize BST - deserialize的非递归版本要用单调栈来把复杂度降低到O(n)
Serilization and Deserialize n-ary Tree
n叉树:
L619 Binary Tree Longest Consecutive Sequence III -- L614的n叉树follow up
other Related:
314 Binary Tree Vertical Order Traversal -- HashTable
987 Vertical Order Traversal of a Binary Tree -- same as 314 排序方法不一样而已
L392 House Robber I - DP
L535 House Robber II - DP
L126 Max Tree - cartesian tree 单调栈
Last updated