Leetcode Tree篇

201 阅读1分钟

543. Diameter of Binary Tree   用两条边的返回值计算更新全局变量,递归返回单边结果

124. Binary Tree Maximum Path Sum  跟543相似

687. Longest Univalue Path   同类题

337. House Robber III  这一系列都要分exclude和include两种情况考虑

112. Path Sum  简化的DFS,只判断是否存在解

113. Path Sum II   找到所有解,注意合并重复的代码!

437. Path Sum III  不需要root to leaf,map

110. Balanced Binary Tree    一旦找到解就不再继续搜索,返回值为-1代表false

111. Minimum Depth of Binary Tree  

**572. Subtree of Another Tree **  分解成左右子问题

**965. Univalued Binary Tree   **分解成左右子问题

129. Sum Root to Leaf Numbers    分解成左右子问题  medium

**257. Binary Tree Paths   **DFS

**236. Lowest Common Ancestor of a Binary Tree  **

102. Binary Tree Level Order Traversal  top down

**107. Binary Tree Level Order Traversal II   **bottom up

**429. N-ary Tree Level Order Traversal **   还是层次遍历

**1302. Deepest Leaves Sum **

872. Leaf-Similar Trees   把dfs写成generator的形式

树剪枝系列

814. Binary Tree Pruning   分解成左右子问题 

669. Trim a Binary Search Tree   分解成左右子问题

**1325. Delete Leaves With a Given Value   **

前中后序遍历

**94. Binary Tree Inorder Traversal  **

144. Binary Tree Preorder Traversal

**589. N-ary Tree Preorder Traversal **

590. N-ary Tree Postorder Traversal

**979. Distribute Coins in Binary Tree   ** flow代表移动次数

508. Most Frequent Subtree Sum