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类:

129 Sum Root to Leaf Numbers

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比加起来方便------

112 Path Sum

113 Path Sum II (L376 Binary Tree Path Sum)

437 Path Sum III -- 跟L246一样,只是这题求的是方案个数,L246求具体方案

L246 Binary Tree Path Sum II

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

543 Diameter of Binary Tree

Tree Node Sum/Value类:

L597 Subtree with Maximum Average

L596 minimum Subtree

L628 Maximum Subtree

501 Find Mode in Binary Search Tree

333 Largest BST Subtree

508 Most Frequent Subtree Sum

404 Sum of Left Leaves

563 Binary Tree Tilt

1022 Sum of Root To Leaf Binary Numbers

617 Merge Two Binary Trees

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

652 Find Duplicate Subtrees

修改树:

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 感觉是在修改特殊的链表

L375 Clone Binary Tree

538 Convert BST to Greater Tree (L661)

814 Binary Tree Pruning

669 Trim a Binary Search Tree

基本变形考:

模板

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

938 Range Sum of BST

Traversal Related:

99 Recover Binary Search Tree

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

285 Inorder Successor in BST

510 Inorder Successor in BST II

545 Boundary of Binary Tree

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

582 Kill Process

637 Average of Levels in Binary Tree

690 Employee Importance

1245 Tree Diameter

623 Add One Row to 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)

250 Count Univalue Subtrees

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

L527 Trie Serialization

n叉树:

Trie

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 单调栈

线段树(Segment Tree)

Last updated